【发布时间】:2020-12-04 00:28:29
【问题描述】:
我有一个只有几个“应该”和“过滤器”的查询,但其中一个过滤器有一个包含约 20,000 个词条的词条查询。我们的 max_terms_count 是 200k,但这是在抱怨“条款”。
原因:org.elasticsearch.ElasticsearchException:Elasticsearch 异常 [type=too_many_clauses,reason=too_many_clauses:maxClauseCount 设置为 1024]
我编写了包含术语查询的查询,其中的术语远多于此。为什么此查询会导致“子句过多”错误?如何重写此查询以获得相同的结果而不会出现错误?
{
"query" : {
"bool" : {
"filter" : [
{
"nested" : {
"query" : {
"range" : {
"dateField" : {
"from" : "2019-12-03T21:34:30.653Z",
"to" : "2020-12-02T21:34:30.653Z",
"include_lower" : true,
"include_upper" : true,
"boost" : 1.0
}
}
},
"path" : "observed_feeds",
"ignore_unmapped" : false,
"score_mode" : "none",
"boost" : 1.0
}
}
],
"should" : [
{
"bool" : {
"filter" : [
{
"terms" : {
"ipAddressField" : [
"123.123.123.123",
"124.124.124.124",
... like 20,000 of these
],
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"minimum_should_match" : "1",
"boost" : 1.0
}
}
}
编辑:一个注释 - 我将术语查询包装在应该 -> bool 中的原因是因为有时我们需要将多个术语查询 OR'd 在一起。这恰好不是其中之一。
【问题讨论】:
标签: elasticsearch