# Failed to create query - maxClauseCount is set to 1024

**URL:** <https://discuss.elastic.co/t/failed-to-create-query-maxclausecount-is-set-to-1024/302898>\
**Category:** Elasticsearch\
**Created:** [April 21, 2022, 10:49am UTC](https://discuss.elastic.co/t/failed-to-create-query-maxclausecount-is-set-to-1024/302898 "2022-04-21T10:49:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sowmiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sowmiya/32/104623_2.png) [@Sowmiya](https://discuss.elastic.co/u/Sowmiya)\
**Post date:** [April 21, 2022, 10:49am UTC](https://discuss.elastic.co/t/failed-to-create-query-maxclausecount-is-set-to-1024/302898/1 "2022-04-21T10:49:45Z")

</div>

Hi Team,

I am using Elasticsearch version 7.16.2. Have set up the search on the domain-specific data around 20k records. When I am searching for a particular query, I am getting the below error.

_**RequestError(400, 'search\_phase\_execution\_exception', 'failed to create query: maxClauseCount is set to 1024')**_

I ran the _\_analyze_ on that particular query with the analyzer I am using.  
The token count is 35.

Can anyone help me here?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 22, 2022, 3:36am UTC](https://discuss.elastic.co/t/failed-to-create-query-maxclausecount-is-set-to-1024/302898/2 "2022-04-22T03:36:42Z")

</div>

I found this doc and recommend reading it.

Apparently you can change the maxClauseCount value but it doesn't seem to be recommended because it affects memory and cpu performance.

> This setting limits the number of clauses a Lucene BooleanQuery can have. The default of 1024 is quite high and should normally be sufficient. This limit does not only affect Elasticsearchs `bool` query, but many other queries are rewritten to Lucene’s BooleanQuery internally. The limit is in place to prevent searches from becoming too large and taking up too much CPU and memory. In case you’re considering increasing this setting, make sure you’ve exhausted all other options to avoid having to do this. Higher values can lead to performance degradations and memory issues, especially in clusters with a high load or few resources.

> **[Search settings | Elasticsearch Guide \[7.16\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.16/search-settings.html)**

---

<div class="post-metadata">

**Author:** ![Sowmiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sowmiya/32/104623_2.png) [@Sowmiya](https://discuss.elastic.co/u/Sowmiya)\
**Post date:** [April 22, 2022, 5:50am UTC](https://discuss.elastic.co/t/failed-to-create-query-maxclausecount-is-set-to-1024/302898/3 "2022-04-22T05:50:40Z")

</div>

@RabBit_BR thanks for responding

I would like to know what causes this issue.

Let's consider the query: 'a'

1. In the setting this 'a' is having the multiple synonyms like, "synonyms: ['b,a', 'c,a' , 'd,a', 'f,a',]
2. My search looks like this  
"query": { "bool": {  
"filter": [],  
"must": [{ "multi\_match": { "query": a , "fields": [field1, field2 } }],  
"should": [{ "term": { "field": { "value": "dummy value", "boost": 2 } } }] } } }

If you help me with what could be causing the issue, that would be helpful for me to find an alternative approach.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 22, 2022, 1:39pm UTC](https://discuss.elastic.co/t/failed-to-create-query-maxclausecount-is-set-to-1024/302898/4 "2022-04-22T13:39:39Z")

</div>

Look at this solution, similar to your problem.

> [@maxClauseCount error on Multi Match after Upgrade to 7.10.1](https://discuss.elastic.co/t/maxclausecount-error-on-multi-match-after-upgrade-to-7-10-1/266160):
>
> We are in the process of upgrading from Elasticsearch 6.5.4 to 7.10.1. We have some searches that worked fine against 6.5.4 but are getting "failed to create query: maxClauseCount is set to 1024" errors against 7.10.1. Here is an example of the query: "query": { "bool": { "must": [ { "query\_string": { "default\_operator": "and", "fields": [ "field1^4", "field2^3", …

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 20, 2022, 1:39pm UTC](https://discuss.elastic.co/t/failed-to-create-query-maxclausecount-is-set-to-1024/302898/5 "2022-05-20T13:39:52Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
