{
  "id": "elasticsearch/too-many-clauses",
  "signature": "TooManyClausesException: maxClauseCount is set to 1024",
  "signature_zh": "TooManyClausesException: maxClauseCount设置为1024",
  "regex": "maxClauseCount is set to \\d+",
  "domain": "elasticsearch",
  "category": "query_error",
  "subcategory": null,
  "root_cause": "Boolean query or filter contains more than the allowed number of clauses (default 1024), often due to large terms lookup or many should clauses.",
  "root_cause_type": "generic",
  "root_cause_zh": "布尔查询或过滤器包含的条款数超过允许值（默认1024），通常由大型terms查询或多个should子句引起。",
  "versions": [
    {
      "version": "elasticsearch 8.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "elasticsearch 8.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "elasticsearch 8.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "elasticsearch 7.17",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "opensearch 2.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Maskes the symptom but can cause OOM or severe performance degradation; not a sustainable fix for large queries.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Terms query still counts as multiple clauses internally; does not bypass the limit.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The limit is a static setting; restart does not change the clause count for the same query.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Refactor query to use a filters aggregation or nested boolean with minimum_should_match to reduce clause count. Example: POST /my_index/_search { \"query\": { \"bool\": { \"should\": [ { \"term\": { \"field\": \"value1\" } }, { \"term\": { \"field\": \"value2\" } } ], \"minimum_should_match\": 1 } } }",
      "success_rate": 0.85,
      "how": "Refactor query to use a filters aggregation or nested boolean with minimum_should_match to reduce clause count. Example: POST /my_index/_search { \"query\": { \"bool\": { \"should\": [ { \"term\": { \"field\": \"value1\" } }, { \"term\": { \"field\": \"value2\" } } ], \"minimum_should_match\": 1 } } }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Increase max_clause_count dynamically via cluster settings: PUT _cluster/settings { \"persistent\": { \"indices.query.bool.max_clause_count\": 2048 } }",
      "success_rate": 0.75,
      "how": "Increase max_clause_count dynamically via cluster settings: PUT _cluster/settings { \"persistent\": { \"indices.query.bool.max_clause_count\": 2048 } }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a terms lookup from a document field to reduce clause count: POST /my_index/_search { \"query\": { \"terms\": { \"field\": { \"index\": \"lookup_index\", \"id\": \"doc_id\", \"path\": \"target_field\" } } } }",
      "success_rate": 0.8,
      "how": "Use a terms lookup from a document field to reduce clause count: POST /my_index/_search { \"query\": { \"terms\": { \"field\": { \"index\": \"lookup_index\", \"id\": \"doc_id\", \"path\": \"target_field\" } } } }",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "重构查询，使用过滤器聚合或嵌套布尔查询并设置minimum_should_match以减少子句数量。",
    "通过集群设置动态增加max_clause_count。",
    "使用terms lookup从文档字段中获取值，减少子句数量。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.elastic.co/guide/en/elasticsearch/reference/current/search-settings.html#search-settings-max-clause-count",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}