Difference between must_not and filter in elasticsearch

后端 未结 2 1118
天涯浪人
天涯浪人 2021-02-20 06:22

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

相关标签:
2条回答
  • 2021-02-20 06:55

    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.

    0 讨论(0)
  • 2021-02-20 06:59

    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:

    1. It is written in Filter context.
    2. It does not affect the score of the result.
    3. The matched query results will appear in the result.
    4. Exact match based, not partial match.

    must_not:

    1. It is written again on the same filter context.
    2. Which means it will not affect the score of the result.
    3. The documents matched with this condition will NOT appear in the result.
    4. Exact match based.

    0 讨论(0)
提交回复
热议问题