无法找到文档中minimum_should_match的默认值

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html

0还是1,还是取决于查询是否只有shouldfilter上下文?

最佳答案

minimum_should_match的默认值取决于查询和上下文:

  • 1:仅在query contextshould中(不包括mustfilter)
  • 1:在filter context中(例如,在filter查询的bool部分内部;在ES 6.7之前为true)
  • 0:在filter context中(例如在filter查询的bool部分内部;自ES 7.0起为真,请参见下面的注释)
  • 0:在query context中,有mustshould(或filtershould)

  • 可以在 bool 查询的文档中找到:



    一些例子

    查询上下文和should是单独的:
    POST _search
    {
      "query": {
        "bool" : {
          "should" : [
            { "term" : { "tag" : "wow" } },
            { "term" : { "tag" : "elasticsearch" } }
          ]
          # default:
          # "minimum_should_match" : 1
        }
      }
    }
    

    查询上下文和must以及should:
    POST _search
    {
      "query": {
        "bool" : {
          "must" : {
            "term" : { "user" : "kimchy" }
          },
          "should" : [
            { "term" : { "tag" : "wow" } },
            { "term" : { "tag" : "elasticsearch" } }
          ]
          # default:
          # "minimum_should_match" : 0
        }
      }
    }
    

    过滤器上下文:
    POST _search
    {
      "query": {
        "bool": {
          "filter": {
            "bool": {
              "must": {
                "term" : { "user" : "kimchy" }
              },
              "should": [
                { "term" : { "tag" : "wow" } },
                { "term" : { "tag" : "elasticsearch" } }
              ]
              # default (until ES 6.7):
              # "minimum_should_match" : 1
            }
          }
        }
      }
    }
    

    更新:与ES 7.0相关的更改

    在Elasticsearch 7.0中the filter context has been removed,这实际上意味着在过滤器上下文中,其默认值现在为0

    感谢this answer帮助我发现了这一点。

    关于elasticsearch - minimum_should_match的默认值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48984706/

    10-11 12:29