【问题标题】:Not able to change "maxClauseCount" value in elastic search无法在弹性搜索中更改“maxClauseCount”值
【发布时间】:2017-10-10 11:53:15
【问题描述】:

我使用的是 ES 5.2.0,在某些查询执行过程中出现以下异常:

 Caused by: NotSerializableExceptionWrapper[too_many_clauses: maxClauseCount is set to 1024]
    at org.apache.lucene.search.BooleanQuery$Builder.add(BooleanQuery.java:125)
    at org.elasticsearch.index.query.BoolQueryBuilder.addBooleanClauses(BoolQueryBuilder.java:449)
    at org.elasticsearch.index.query.BoolQueryBuilder.doToQuery(BoolQueryBuilder.java:418)

解决这个问题。我正在尝试通过在查询下方运行来更改“indices.query.bool.max_clause_count”值

请求:

PUT http://localhost:9200/_all/_settings?preserve_existing=true  
{"indices.query.bool.max_clause_count" : "100000"}

回复:

{
  "error": {
    "root_cause": [
      {
        "type": "remote_transport_exception",
        "reason": "[06LrSZC][localhost:9300][indices:admin/settings/update]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "unknown setting [index.indices.query.bool.max_clause_count] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
  },
  "status": 400
}

我曾经解决但无法解决的参考:

https://www.elastic.co/guide/en/elasticsearch/reference/5.0/breaking_50_settings_changes.html#_search_settings

https://discuss.elastic.co/t/5-0-0-alpha2-how-to-set-index-query-bool-max-clause-count/49816

https://github.com/elastic/elasticsearch/pull/18341

请让我知道执行此操作的正确请求 JSON。

【问题讨论】:

    标签: elasticsearch elasticsearch-5


    【解决方案1】:

    indices.query.bool.max_clause_count 是一个静态设置,所以你应该在 elasticsearch 集群的每个节点的elasticsearch.yml 文件中设置它。您必须重新启动集群。

    使用以下行更新您的 elasticsearch.yml 文件:

    indices.query.bool.max_clause_count: 100000
    

    注意:只能使用 API 更新动态设置

    【讨论】:

      【解决方案2】:

      这是一个全局设置,不是一级索引,它的位置在 elasticsearch.yml 文件中:

      indices.query.bool.max_clause_count: 10000
      

      这就是为什么它也从index(单数)重命名为indices(复数)。

      【讨论】:

        【解决方案3】:

        查看列表的另一种可能更好的方法是将 mustNots 的数量减少到具有多个术语的单个 must not。这将被视为单个 mustNot 并且不会触发异常,从而允许您保留应用程序中其他地方可能需要的子句限制。 例如 上面的代码将获得一个 airportCode 列表,并且一次“mustNot”它们一个

        // adding the blacklisted carriers to the query
        BannedAirportCodeCache.instance().getAirportCodes()
            .forEach(airportCode-> boolQueryBuilder.mustNot(QueryBuilders
                .matchQuery("airportcodes.raw", airportCode)));
        

        而上面的代码会做同样的事情,但在一个 mustNot 中,它不会触发 tooManyClauses

        QueryBuilder termsQueryBuilder = QueryBuilders
            .termsQuery("airportcodes.raw", BannedAirportCodeCache.instance().getAirportCodes());
        boolQueryBuilder.mustNot(termsQueryBuilder);
        

        【讨论】:

          猜你喜欢
          • 2016-02-27
          • 2020-12-06
          • 1970-01-01
          • 2017-12-15
          • 1970-01-01
          • 2019-05-18
          • 2022-08-12
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多