Can someone explain to me what the difference between must_not and filter is in elasticsearch?
E.g. here (taken from elasticsearch definitive guide), why isn't must_not also used for the range?
{
"bool": {
"must": { "match": { "title": "how to make millions" }},
"must_not": { "match": { "tag": "spam" }},
"should": [
{ "match": { "tag": "starred" }}
],
"filter": {
"range": { "date": { "gte": "2014-01-01" }}
}
}
}
Specifically looking at this documentation, it appears to me that they are exactly the same:
filter: The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching.
must_not: The clause (query) must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored and clauses are considered for caching. Because scoring is ignored, a score of 0 for all documents is returned.
must_not
constraint as above by usingfilter
instead ofmust_not
? – Val