【问题标题】:Problems with large bool on elasticsearchelasticsearch 上的大布尔问题
【发布时间】:2017-02-14 17:35:10
【问题描述】:

我需要从超过 1024 个的列表中获取至少包含一项的所有文档。

我的查询基本上是一个 bool 查询,带有 shouldminimum_should_match: 1

Elasticsearch maxClauseCount 默认设置为 1024。我尝试将其设置为 4096,并且配置看起来还可以:

我请求http://myserver:9200/my_index/_settings 并得到:

... "query": { "bool": { "max_clause_count": "4096" } } ..., 但如果我尝试仍然在我的日志中获得TooManyClauses[maxClauseCount is set to 1024]

第一个问题:为什么会这样矛盾?

我已经读到,在某些情况下,最好使用过滤器而不是大布尔值:

一般来说,我建议重写该查询以使用术语过滤器而不是布尔查询 https://discuss.elastic.co/t/too-many-clauses-maxclausecount-is-set-to-1024/61968

第二个问题:如何使用过滤器来获得与我的示例中的倍数应该 bool 相同的逻辑?这种情况下最好的布尔过滤器或过滤过滤器是什么?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    我还不确定 Elasticsearch 为什么会引发 maxClauseCount 错误,但我找到了另一种构建查询的方法。

    (简单的)解决方案是使用包含大量项目的术语。如果我在must 中使用它,我会遇到同样的错误,但使用filter 它可以完美运行。

    例子:

    {
      "query": {
        "bool": {
          "filter": [
            {"terms": {"my_field": ["item1", "item2", ... "itemN"]}}
          ]
        }
      }
    }
    

    filter 唯一的不足是:

    子句(查询)必须出现在匹配的文档中。然而,与必须不同,查询的分数将被忽略。 https://www.elastic.co/guide/en/elasticsearch/reference/2.3/query-dsl-bool-query.html

    【讨论】:

      猜你喜欢
      • 2016-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-03
      • 1970-01-01
      • 2012-11-27
      • 1970-01-01
      相关资源
      最近更新 更多