I'm using ElasticSearch to search a mongodb with python. I'd like to give the query a list of item ids in order to exclude them from the search results.
I tried with this query but I get no results:
flagged_articles = ["er12", "rt43"]
query = {
"from": page*limit,
"size": limit,
"query": {
"bool": {
"must": {
"range": {
"added" : {
"from" : "2013-04-11T00:00:00"
}
}
},
"ids" : {
"values" : flagged_articles
}
}
It would be faster if you did this with a filter rather than a query. A filter doesn't do any score calculation and so has a lighter overhead.
{
"filtered" : {
"query" : {
"range": {
"added" : {
"from" : "2013-04-11T00:00:00"
}
}
},
"filter" : {
"not" : {
"filter" : {
"ids" : {
"values" : ["123", "456", "789"]
}
},
"_cache" : true
}
}
}
}
NOTE: The not
filter is not cached by default (the other filters are usually cached). I've added a _cache: true
parameter to show you have to cache the not
filter if you think you will be using it on subsequent searches.
Good luck!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments