Skip to content

Instantly share code, notes, and snippets.

@brwe
Created October 19, 2013 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brwe/7056487 to your computer and use it in GitHub Desktop.
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.
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"
}
}
}'
@brwe
Copy link
Author

brwe commented Oct 19, 2013

If you want the original score to be added to the script score, replace "boost_mode": "replace" with "boost_mode": "sum".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment