Elasticsearch difference between MUST and SHOULD bool query

前端 未结 3 1957
难免孤独
难免孤独 2020-12-07 08:27

What is the difference between MUST and SHOULD bool query in ES?

If I ONLY want results that contain my terms should I the

3条回答
  •  無奈伤痛
    2020-12-07 08:52

    As said in the documentation:

    Must: The clause (query) must appear in matching documents.

    Should: The clause (query) should appear in the matching document. In a boolean query with no must clauses, one or more should clauses must match a document. The minimum number of should clauses to match can be set using the minimum_should_match parameter.

    In other words, results will have to be matched by all the queries present in the must clause ( or match at least one of the should clauses if there is no must clause.

    Since you want your results to satisfy all the queries, you should use must.


    You can indeed use filters inside a boolean query.

提交回复
热议问题