@Es problem -- too many bool conditions (1024)

Keywords: Programming ElasticSearch

Background: too many splices in boo query result in 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": "senile dementia",
              "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",
    ......
    }
}

Reason: the reason for error reporting is that Search limits a bool query to a maximum of 1024 values or subqueries. When it exceeds 1024, an exception will be thrown times.

terms of settlement:

  • Scheme 1: when the number is over 1024, a bool query can be divided into two sub bool queries. The most keyword is used to make the two sub bool queries be the relationship between and
  • Scheme 2: edit elasticsearch.yml and add the following configuration
index.query.bool.max_clause_count: 10240

Note: a space must be added at the front, that is, it must be aligned with other configuration initials, otherwise es will start to report errors.

Posted by bdee1 on Mon, 20 Apr 2020 10:33:13 -0700