Skip to content

Instantly share code, notes, and snippets.

@jprante
Created January 31, 2014 09:29
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 jprante/8728976 to your computer and use it in GitHub Desktop.
Save jprante/8728976 to your computer and use it in GitHub Desktop.
Document boosting with function score query
curl -XDELETE 'localhost:9200/test'
curl -XPUT 'localhost:9200/test/doc/1' -d '
{
"sentence" : "less important",
"boost" : 0.5
}
'
curl -XPUT 'localhost:9200/test/doc/2' -d '
{
"sentence" : "quite important",
"boost" : 2.0
}
'
curl -XPUT 'localhost:9200/test/doc/3' -d '
{
"sentence" : "more important",
"boost" : 3.0
}
'
curl -XPUT 'localhost:9200/test/doc/4' -d '
{
"sentence" : "who cares about this document",
"boost" : 1.0
}
'
curl 'localhost:9200/test/_refresh'
# boost as linear decay function
curl -XPOST 'localhost:9200/test/_search' -d '
{
"query": {
"function_score": {
"query" : {
"query_string" : {
"query" : "sentence:important"
}
},
"functions": [
{
"filter": {
"range": {
"boost": {
"gte": 0.0,
"lte": 10.0
}
}
},
"linear": {
"boost": {
"origin": 10,
"scale": 10,
"decay": 0.1
}
}
}
],
"boost" : 100.0,
"max_boost" : 10.0,
"boost_mode" : "multiply",
"score_mode": "multiply"
}
}
}
'
# boost with script_score
curl -XPOST 'localhost:9200/test/_search' -d '
{
"query": {
"function_score": {
"query" : {
"query_string" : {
"query" : "sentence:important"
}
},
"functions": [
{
"filter": {
"range": {
"boost": {
"gte": 0.0,
"lte": 10.0
}
}
},
"script_score" : {
"script" : "_score * doc[\"boost\"].value"
}
}
],
"boost" : 100.0,
"max_boost" : 10.0,
"boost_mode" : "multiply",
"score_mode": "multiply"
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment