小编典典

minimum_should_match的默认值?

elasticsearch

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

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

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


阅读 1397

收藏
2020-06-22

共1个答案

小编典典

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

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

如果布尔查询位于查询上下文中,并且具有must或filter子句,则文档将与布尔查询匹配,即使没有应当匹配的查询。在这种情况下,这些子句仅用于影响得分。如果布尔查询是一个过滤器上下文,或者既没有必须查询也没有过滤器,则应该查询中的至少一个必须与文档匹配才能使其与布尔查询匹配。可以通过设置minimum_should_match参数来明确控制此行为。

一些例子

查询上下文,并且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中,过滤器上下文已被删除,这实际上意味着在过滤器上下文中其默认值现在为0

2020-06-22