too_many_clauses: too_many_clauses: maxClauseCount is set to 1024 (query contains too many clauses)
ElasticsearchWhat does it mean?
A query exceeded the maximum allowed number of Lucene clauses. In ES 8.x this limit is not fixed; it is calculated automatically from the node's heap size and search thread count (it can drop to 1024 on small-heap nodes), and the error message shows the current value. Very large bool queries and queries that expand to many terms trigger it.
Why does it happen?
Programmatically generated bool queries with thousands of should/must clauses; wildcard/prefix/fuzzy/query_string queries expanding to many terms; deeply nested bool structures. Note: the terms query (a value list on a single field) is not subject to this limit; its cap is index.max_terms_count (default 65,536).
How to fix it
Simplify the query: convert many term clauses on a single field into one terms query (or a terms lookup for large lists). Use more specific query types or index_prefixes/keyword fields instead of wildcard/prefix. In ES 8.x the indices.query.bool.max_clause_count setting is deprecated and ignored; the way to raise the limit is to increase the node heap. Review the query generation logic.
More from this engine
- strict_dynamic_mapping_exceptionstrict_dynamic_mapping_exception: mapping set to strict, dynamic introduction of [...] within [...] is not allowed
- illegal_argument_exception_fielddataillegal_argument_exception: Fielddata is disabled on text fields by default. Set fielddata=true on [your_field] in order to load fielddata in memory
- search_phase_execution_exceptionsearch_phase_execution_exception: all shards failed / Failed to execute phase [query]
- version_conflict_engine_exceptionversion_conflict_engine_exception: [_doc][id]: version conflict, current version [x] is different than the one provided [y] (HTTP 409)
- document_missing_exceptiondocument_missing_exception: [_doc][id]: document missing
- index_not_found_exceptionindex_not_found_exception: no such index [index_name] (HTTP 404)
- resource_already_exists_exceptionresource_already_exists_exception: index [index_name/uuid] already exists (HTTP 400)