Difference between must_not and filter in elasticsearch
Basically, filter
= must
but without scoring.
must_not
expresses a condition that MUST NOT be met, while filter
(and must
) express conditions that MUST be met in order for a document to be selected.
The filter
is used when the matched documents need to be shown in the result, while must_not
is used when the matched documents will not be shown in the results. For further analysis:
filter:
- It is written in Filter context.
- It does not affect the score of the result.
- The matched query results will appear in the result.
- Exact match based, not partial match.
must_not:
- It is written again on the same filter context.
- Which means it will not affect the score of the result.
- The documents matched with this condition will NOT appear in the result.
- Exact match based.