Skip to content

Instantly share code, notes, and snippets.

@avar
Forked from kimchy/gist:2003665
Created March 8, 2012 21:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avar/2003675 to your computer and use it in GitHub Desktop.
Save avar/2003675 to your computer and use it in GitHub Desktop.
curl -XPUT localhost:9200/test -d '{
"settings" : {
"index.number_of_shards" : 1,
"index.number_of_replicas" : 0
}
}'
curl -XPUT localhost:9200/test/type/1 -d '{
"name" : "Awesometastic 1000",
"type" : "TV Remote"
}'
curl -XPUT localhost:9200/test/type/2 -d '{
"name" : "Awesometastic 1000 TV Remote",
"type" : "TV Remote"
}'
curl -XPOST localhost:9200/test/_refresh
# One without negative boosting
curl 'localhost:9200/test/_search?pretty=1&explain=0' -d '{
"query" : {
"bool" : {
"should" : [
{ "text" : {"name" : {"query" : "The Awesometastic TV Remote", "boost" : 10}} },
{ "text" : {"type" : {"query" : "The Awesometastic TV Remote", "boost" : 5}} },
]
}
}
}'
# The query that gives us ones that try and cheat the system (higher score means that they are trying to cheat more...)
curl 'localhost:9200/test/_search?pretty=1&explain=0' -d '{
"query" : {
"bool" : {
"must" : [
{ "text" : {"name" : {"query" : "The Awesometastic TV Remote", "boost" : 1}} },
{ "text" : {"type" : {"query" : "The Awesometastic TV Remote", "boost" : 1}} }
],
"boost" : 1
}
}
}'
# Now, combine the two, should clauses are sums of scores, so have the negative boost query boost by a negative factor
curl 'localhost:9200/test/_search?pretty=1&explain=0' -d '{
"query" : {
"bool" : {
"should" : [
{ "text" : {"name" : {"query" : "The Awesometastic TV Remote", "boost" : 10}} },
{ "text" : {"type" : {"query" : "The Awesometastic TV Remote", "boost" : 5}} },
{
"bool" : {
"must" : [
{ "text" : {"name" : {"query" : "The Awesometastic TV Remote", "boost" : 1}} },
{ "text" : {"type" : {"query" : "The Awesometastic TV Remote", "boost" : 1}} }
],
"boost" : -20
}
}
]
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment