While these two are giving me the same result, what is the difference between having the filter inside or outside? Is there a difference in terms of performance or the actions behind the scenes?
"query": {
"filtered": {
"query": { "match": { "email": "business opportunity" }},
"filter": { "term": { "folder": "inbox" }}
}
}
"query": {
"filtered": {
"query": { "match": { "email": "business opportunity" }}
}
},
"filter": {
"term": { "folder": "inbox" }
}
Elasticsearch will execute the query and filter in what ever way is more efficient to reduce the results set and get you the answer as quickly as possible. This is referred to as a filtered_query
The query is run first and then results are filtered before returning them to the client. This is referred to as a post_filter.
Although a post_filter is less efficient, it can be useful when combining with an aggregation - the aggregated values won't take into account the post_filter, i.e. the aggregation will only be on the query results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With