Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2012 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4246795 to your computer and use it in GitHub Desktop.
Save anonymous/4246795 to your computer and use it in GitHub Desktop.
############################################################
# create some documents, index "test", type "test"
curl -XPUT http://localhost:9200/test/test/1 -d '{
"title": "colour",
"tags" : ["red", "blue", "green"]
}'
curl -XPUT http://localhost:9200/test/test/2 -d '{
"title": "colour",
"tags" : ["red"]
}'
curl -XPUT http://localhost:9200/test/test/3 -d '{
"title": "colour",
"tags" : ["green"]
}'
curl -XPUT http://localhost:9200/test/test/4 -d '{
"title": "colour",
"tags" : ["blue"]
}'
curl -XPUT http://localhost:9200/test/test/5 -d '{
"title": "colour",
"tags" : ["red", "blue", "green"]
}'
curl -XPUT http://localhost:9200/test/test/6 -d '{
"title": "colour",
"tags" : ["red", "blue"]
}'
curl -XPUT http://localhost:9200/test/test/7 -d '{
"title": "magic",
"tags" : ["red", "green", "blue"]
}'
##################################################################
# get documents with "colour" in title that are either red or blue
curl -XPOST http://localhost:9200/test/_search -d '{
"query": {
"filtered": {
"filter": {
"and": [
{
"terms": {
"tags": [
"red",
"blue"
]
}
}
]
},
"query": {
"bool": {
"must": [
{
"query_string": {
"fields": [
"title"
],
"query": "colour",
"default_operator": "AND"
}
}
]
}
}
}
}
}'
# (returns 5 documents, correctly)
########################################################################
# now try to rank some "red" documents higher, by boosting with 2.0
curl -XPOST http://localhost:9200/test/_search -d '{
"query": {
"custom_filters_score": {
"score_mode": "max",
"filters": [
{
"filter": {
"term": {
"tags": "red"
}
},
"boost": 2
},
{
"filter": {
"term": {
"tags": "blue"
}
},
"boost": 1
}
],
"query": {
"bool": {
"must": [
{
"query_string": {
"fields": [
"title"
],
"query": "colour",
"default_operator": "AND"
}
}
]
}
}
}
}
}'
# incorrectly returns 6 documents... id=3 with "green" is in results too
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment