Last active
August 29, 2015 14:01
Elasticsearch MVEL score calculation: Multiply when field is present
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XPUT localhost:9200/test | |
curl -XPUT localhost:9200/test/mock/_mapping -d '{mock: {properties: {x: {type: "integer"},y: {type: "integer"}}}}' | |
curl -XPUT localhost:9200/test/mock/1 -d '{x:5, y:6}' | |
# Score should be 30 | |
curl 'localhost:9200/test/mock/_search' -d '{query: {function_score: {query: {match_all:{}},functions: [{"script_score": {script: "doc[\"x\"].value * (doc.containsKey(\"y\") ? doc[\"y\"].value : 1)"}}]}}}' | |
# Score should be 5 | |
curl 'localhost:9200/test/mock/_search' -d '{query: {function_score: {query: {match_all:{}},functions: [{"script_score": {script: "doc[\"x\"].value * (doc.containsKey(\"z\") ? doc[\"z\"].value : 1)"}}]}}}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment