Created
December 9, 2012 20:14
-
-
Save anonymous/4246795 to your computer and use it in GitHub Desktop.
This file contains 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
############################################################ | |
# 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