@Es问题--bool条件过多(1024)

时光怂恿深爱的人放手 提交于 2020-04-21 03:35:21

背景:boo查询中过多的拼接bool导致报 too_many_clauses: maxClauseCount is set to 1024

{
  "from": 0,
  "size": 10,
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "idx_diseaseid": [
              "DiseaseId_1027"
            ],
            "boost": 1
          }
        },
        {
          "match": {
            "text_all": {
              "query": "老年痴呆",
              "operator": "OR",
              "prefix_length": 0,
              "max_expansions": 50,
              "minimum_should_match": "2<80%",
              "fuzzy_transpositions": true,
              "lenient": false,
              "zero_terms_query": "NONE",
              "auto_generate_synonyms_phrase_query": true,
              "boost": 1
            }
          }
        },
        {
          "term": {
            "idx_facultyid": {
              "value": "FacultyId_1007000",
              "boost": 1
            }
          }
        },
        {
          "bool": {
            "should": [
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "caseopened": {
                          "value": true,
                          "boost": 1
                        }
                      }
                    },
                    {
                      "term": {
                        "confirmed": {
                          "value": 1,
                          "boost": 1
                        }
                      }
                    }
                  ],
                  "adjust_pure_negative": true,
                  "boost": 1
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "phoneopened": {
                          "value": true,
                          "boost": 1
                        }
                      }
                    }
                  ],
                  "adjust_pure_negative": true,
                  "boost": 1
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  },
  "sort": [
    {
      "complexrank": {
        "order": "desc"
      }
    },
    {
      "_score": {
        "order": "desc"
      }
    }
  ]
}
{
"error":
    {"root_cause":
       [
          {"type":"too_many_clauses","reason":"too_many_clauses: maxClauseCount is set to 1024"}
       ],
   "type":"search_phase_execution_exception",
    ……
    }
}

原因:报错原因是Search限制一个bool查询中最多只能有1024个值或子查询,当超过1024时,会抛出次异常。

解决办法:

  • 方案一:当超过1024时可以将一个bool查询拆成两个子bool查询,使用must关键字,使得两个子bool查询是与的关系
  • 方案二:编辑elasticsearch.yml,添加如下配置
index.query.bool.max_clause_count: 10240

注意:必须在最前面添加一个空格,即和其他配置首字母对齐,不然es启动报错。

 

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!