Skip to content

Instantly share code, notes, and snippets.

@augustine-tran
Created November 19, 2013 17:29
Show Gist options
  • Save augustine-tran/7549082 to your computer and use it in GitHub Desktop.
Save augustine-tran/7549082 to your computer and use it in GitHub Desktop.
Scoring document by count matching tags #elasticsearch #function_score_query
curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "One", "tags" : ["foo"]}'
curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "Two", "tags" : ["foo", "bar"]}'
curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "Three", "tags" : ["foo", "bar", "baz"]}'
curl -X POST articles/article/_search
{
"query": {
"function_score": {
"functions": [
{
"script_score": {
"params": {
"param1": ["baz", "bar"]
},
"lang": "groovy",
"script": "_score * param1.intersect(_source.tags).size()"
}
}
]
}
},
"facets": {
"tags": {
"terms": {
"field": "tags",
"size": 10
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment