Administrator
发布于 2023-06-14 / 89 阅读 / 0 评论 / 0 点赞

ES 问题 : too_many_clauses maxClauseCount is set to 1024

ES 问题 : too_many_clauses maxClauseCount is set to 1024

修改elasticsearch.yml配置

#6.0以下添加
index.query.bool.max_clause_count: 10240 
#6.0以上添加
indices.query.bool.max_clause_count: 10240

原因是bool 查询拼接太多了,有一个拼接上限,es默认设置为1024

这个限制是针对同级的条件数做了限制,可以拆成子级的多个条件进行避免!

例如限制是4时,这样的查询是不允许的

{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "content": "xxx1"
          }
        },{
          "match_phrase": {
            "content": "xxx2"
          }
        },{
          "match_phrase": {
            "content": "xxx3"
          }
        },{
          "match_phrase": {
            "content": "xxx4"
          }
        },{
          "match_phrase": {
            "content": "xxx5"
          }
        }
      ],
      "minimum_should_match": 1
    }
  },
  "sort": [
    {
      "created": {
        "order": "desc"
      }
    },
    "created"
  ],
  "from": 0,
  "size": 100
}

拆分成下面这样,就是可以正常执行的:

{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "should": [
              
              {
                "match_phrase": {
                  "content": "xxx1"
                }
              },
              {
                "match_phrase": {
                  "content": "xxx2"
                }
              },
              {
                "match_phrase": {
                  "content": "xxx3"
                }
              },
              {
                "match_phrase": {
                  "content": "xxx4"
                }
              }
            ],
            "minimum_should_match": 1
          }
        },
        {
          "bool": {
            "should": [
              {
                "match_phrase": {
                  "content": "xxx5"
                }
              },
              {
                "match_phrase": {
                  "content": "xxx1915"
                }
              }
            ],
            "minimum_should_match": 1
          }
        }
      ],
      "minimum_should_match": 1
    }
  },
  "sort": [
    {
      "created": {
        "order": "desc"
      }
    },
    "created"
  ],
  "from": 0,
  "size": 100
}

评论