elasticsearch - minimum_should_match 的默认值?

标签 elasticsearch

无法在文档中找到 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 context并且 should 是单独的(没有 mustfilter)
  • 1:在filter context (例如,在 bool 查询的 filter 部分内;在 ES 6.7 之前为真)
  • 0:在 filter context 中(例如,在 bool 查询的 filter 部分内;自 ES 7.0 起为真,请参阅下面的注释)
  • 0:在 query context 中并且有 mustshould(或 filtershould)

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

If the bool query is in a query context and has a must or filter clause then a document will match the bool query even if none of the should queries match. In this case these clauses are only used to influence the score. If the bool query is a filter context or has neither must or filter then at least one of the should queries must match a document for it to match the bool query. This behavior may be explicitly controlled by settings the minimum_should_match parameter.

几个例子

查询上下文和应该是单独的:

POST _search
{
  "query": {
    "bool" : {
      "should" : [
        { "term" : { "tag" : "wow" } },
        { "term" : { "tag" : "elasticsearch" } }
      ]
      # default:
      # "minimum_should_match" : 1
    }
  }
}

查询上下文和必须连同应该:

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/

相关文章:

elasticsearch - Kibana仪表板,而不是我的应用程序仪表板

json - Logstash:将不同的json字段发送到Elasticsearch中的不同类型

scala - 使用elastic4s客户端为Elasticsearch构建动态聚合查询

ubuntu - 如何在 ubuntu 18 上将演示请求发布到 elasticsearch

elasticsearch - 像在SQL中的 “distint count”的elasticsearch搜索?

elasticsearch - Couchbase Elasticsearch Connector保存检查点相同的存储桶

elasticsearch - 计算时间戳是大于还是小于当前时间

arrays - 过滤对象数组

nginx - 在kibana中汇总http日志路径列表

elasticsearch - 在 Elasticsearch 中生成数据表