In a Udemy tutorial I came across this query here:
{ "query": { "bool": {
"must": {"match": {"genre": "Sci-Fi"}},
"must_not": {"match": {"title": "trek"}},
"filter:" {"range": {"year": {"gte": 2010, "lt": 2015}}}
}}}
I was wondering if it's possible to optimize it? I am thinking of two possible ways:
Putting "genre" in a filter context. But a movie might be of multiple genres, so I am not sure if working with type keyword and filter-term would work there.
Putting "must_not" in a filter context directly (without a bool) will not work, because filters as far as I understand do not allow "filtering out", only "filtering what to keep". But if I wrapped must_not in a constant_score or filter-bool, would the query be more performant? Or does ES automatically take care of such optimizations? I just don't understand why must_not is in the query and not filter context in the first place. Can something only partially not match and thus reduce the score only by a degree?