无法在弹性搜索中更改“maxClauseCount”值

问题描述 投票:0回答:3

我正在使用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
3个回答
3
投票

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

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

indices.query.bool.max_clause_count: 100000

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


1
投票

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

indices.query.bool.max_clause_count: 10000

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


0
投票

查看列表的另一种可能更好的方法是将mustNots的数量减少为单个,不得使用多个术语。这将被视为单个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);
© www.soinside.com 2019 - 2024. All rights reserved.