Created
October 19, 2013 14:18
-
-
Save brwe/7056487 to your computer and use it in GitHub Desktop.
function score example that checks for words in a multi valued field and adds 1 if the word was found.
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 -XPOST "http://localhost:9200/scorescripttest/test/" -d' | |
{ | |
"tags": [ | |
"dressing room", | |
"zebrawood", | |
"wood", | |
"oak", | |
"on your person", | |
"seating", | |
"chair", | |
"home", | |
"sophisticated", | |
"furniture", | |
"mahogany" | |
] | |
}' | |
curl -XPOST "http://localhost:9200/scorescripttest/test/_search" -d' | |
{ | |
"query": { | |
"function_score": { | |
"query": { | |
"match": { | |
"tags": "chair" | |
} | |
}, | |
"functions": [ | |
{ | |
"script_score": { | |
"params": { | |
"tags": ["seating", "chair", "mahogany"] | |
}, | |
"script": "score = 0;foreach (value : doc[\"tags\"].values){if(tags contains value){score+=1};} return score;" | |
} | |
} | |
], | |
"boost_mode": "replace" | |
} | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want the original score to be added to the script score, replace
"boost_mode": "replace"
with"boost_mode": "sum"
.