Created
March 8, 2012 21:45
-
-
Save kimchy/2003665 to your computer and use it in GitHub Desktop.
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 -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