# How do I get Elasticsearch max\_clause\_count to take effect?

**URL:** https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133
**Category:** Elasticsearch
**Created:** [December 12, 2011, 11:19pm UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133 "2011-12-12T23:19:04Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![jbattle](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@jbattle](https://discuss.elastic.co/u/jbattle)
#### Post date: [December 12, 2011, 11:19pm UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133/1 "2011-12-12T23:19:04Z")

</div>

I am currently setting the max\_clause\_count at the creation of my  
index as follows:

"index":{  
"type" :"new",  
"bulk\_size":"100000",  
"bulk\_timeout":"1000ms",  
"query":{  
"bool":{  
"max\_clause\_count": 1000000  
}  
}  
}

The setting is refelected when I check my index settings at  
[http://localhost:9200/myindex/\_settings](http://localhost:9200/myindex/_settings) with this line:  
index.query.bool.max\_clause\_count: "1000000"

Despite this, when I run a query, I get the below error stating that  
the max\_clause\_count is the default 1024:  
Caused by: org.apache.lucene.search.BooleanQuery$TooManyClauses:  
maxClauseCount is set to 1024

Any insight to why despite the setting showing the max\_clause\_count as  
set to 1000000, that Elasticsearch is still throwing that error?

Thanks

- justin

---

<div class="post-metadata">

### Author: ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)
#### Post date: [December 13, 2011, 11:23am UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133/2 "2011-12-13T11:23:29Z")

</div>

The setting should go in the elasticsearch config (there where the  
analyzers go), not in the index settings.

And: are you really need more than 1024 clauses (can be bad in terms  
of RAM)? Why not using a boolean filter or a terms filter? Or are you  
hitting the limit because of some query expansion of a different  
query?

Peter.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [December 13, 2011, 2:27pm UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133/3 "2011-12-13T14:27:51Z")

</div>

It can only be set on the config file, not on index creation settings. This  
is because its a static setting in Lucene.

On Tue, Dec 13, 2011 at 1:19 AM, jbattle [jbattle@gmail.com](mailto:jbattle@gmail.com) wrote:

> I am currently setting the max\_clause\_count at the creation of my  
> index as follows:
> 
> "index":{  
> "type" :"new",  
> "bulk\_size":"100000",  
> "bulk\_timeout":"1000ms",  
> "query":{  
> "bool":{  
> "max\_clause\_count": 1000000  
> }  
> }  
> }
> 
> The setting is refelected when I check my index settings at  
> [http://localhost:9200/myindex/\_settings](http://localhost:9200/myindex/_settings) with this line:  
> index.query.bool.max\_clause\_count: "1000000"
> 
> Despite this, when I run a query, I get the below error stating that  
> the max\_clause\_count is the default 1024:  
> Caused by: org.apache.lucene.search.BooleanQuery$TooManyClauses:  
> maxClauseCount is set to 1024
> 
> Any insight to why despite the setting showing the max\_clause\_count as  
> set to 1000000, that Elasticsearch is still throwing that error?
> 
> Thanks
> 
> - justin

---

<div class="post-metadata">

### Author: ![jbattle](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@jbattle](https://discuss.elastic.co/u/jbattle)
#### Post date: [December 13, 2011, 6:31pm UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133/4 "2011-12-13T18:31:44Z")

</div>

Peter,

Thanks for your response. I am using a terms filter where I'm  
filtering against thousands of accounts. It appears this is why I was  
hitting the 1024 limit.

- justin

On Dec 13, 3:23 am, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:

> The setting should go in the elasticsearch config (there where the  
> analyzers go), not in the index settings.
> 
> And: are you really need more than 1024 clauses (can be bad in terms  
> of RAM)? Why not using a boolean filter or a terms filter? Or are you  
> hitting the limit because of some query expansion of a different  
> query?
> 
> Peter.

---

<div class="post-metadata">

### Author: ![jbattle](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@jbattle](https://discuss.elastic.co/u/jbattle)
#### Post date: [December 13, 2011, 6:34pm UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133/5 "2011-12-13T18:34:19Z")

</div>

Shay,

Thank you for your response. I have done this and am no longer bound  
to the 1024 limit.

Much Thanks,

- justin

On Dec 13, 6:27 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> It can only be set on the config file, not on index creation settings. This  
> is because its a static setting in Lucene.
> 
> On Tue, Dec 13, 2011 at 1:19 AM, jbattle [jbat...@gmail.com](mailto:jbat...@gmail.com) wrote:
> 
> > I am currently setting the max\_clause\_count at the creation of my  
> > index as follows:
> 
> > "index":{  
> > "type" :"new",  
> > "bulk\_size":"100000",  
> > "bulk\_timeout":"1000ms",  
> > "query":{  
> > "bool":{  
> > "max\_clause\_count": 1000000  
> > }  
> > }  
> > }
> 
> > The setting is refelected when I check my index settings at  
> > [http://localhost:9200/myindex/\_settingswith](http://localhost:9200/myindex/_settingswith) this line:  
> > index.query.bool.max\_clause\_count: "1000000"
> 
> > Despite this, when I run a query, I get the below error stating that  
> > the max\_clause\_count is the default 1024:  
> > Caused by: org.apache.lucene.search.BooleanQuery$TooManyClauses:  
> > maxClauseCount is set to 1024
> 
> > Any insight to why despite the setting showing the max\_clause\_count as  
> > set to 1000000, that Elasticsearch is still throwing that error?
> 
> > Thanks
> > 
> > - justin

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [December 13, 2011, 10:31pm UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133/6 "2011-12-13T22:31:22Z")

</div>

Terms filter is not bounded by the max clause count, only the bool query.

On Tue, Dec 13, 2011 at 8:34 PM, jbattle [jbattle@gmail.com](mailto:jbattle@gmail.com) wrote:

> Shay,
> 
> Thank you for your response. I have done this and am no longer bound  
> to the 1024 limit.
> 
> Much Thanks,
> 
> - justin
> 
> On Dec 13, 6:27 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > It can only be set on the config file, not on index creation settings.  
> > This  
> > is because its a static setting in Lucene.
> > 
> > On Tue, Dec 13, 2011 at 1:19 AM, jbattle [jbat...@gmail.com](mailto:jbat...@gmail.com) wrote:
> > 
> > > I am currently setting the max\_clause\_count at the creation of my  
> > > index as follows:
> > 
> > > "index":{  
> > > "type" :"new",  
> > > "bulk\_size":"100000",  
> > > "bulk\_timeout":"1000ms",  
> > > "query":{  
> > > "bool":{  
> > > "max\_clause\_count": 1000000  
> > > }  
> > > }  
> > > }
> > 
> > > The setting is refelected when I check my index settings at  
> > > [http://localhost:9200/myindex/\_settingswith](http://localhost:9200/myindex/_settingswith) this line:  
> > > index.query.bool.max\_clause\_count: "1000000"
> > 
> > > Despite this, when I run a query, I get the below error stating that  
> > > the max\_clause\_count is the default 1024:  
> > > Caused by: org.apache.lucene.search.BooleanQuery$TooManyClauses:  
> > > maxClauseCount is set to 1024
> > 
> > > Any insight to why despite the setting showing the max\_clause\_count as  
> > > set to 1000000, that Elasticsearch is still throwing that error?
> > 
> > > Thanks
> > > 
> > > - justin

---

<div class="post-metadata">

### Author: ![icenine18](https://avatars.discourse-cdn.com/v4/letter/i/3be4f8/32.png) [@icenine18](https://discuss.elastic.co/u/icenine18)
#### Post date: [December 13, 2011, 11:43pm UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133/7 "2011-12-13T23:43:18Z")

</div>

Is the setting being referred to in the elasticsearch yaml file?:

query:  
bool:  
max\_clause\_count: 10240

I've increased the value of this setting on my cluster, but am still  
receiving the clause limit error using the Java API for certain  
queries. thanks.

On Dec 13, 5:31 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Terms filter is not bounded by the max clause count, only the bool query.
> 
> On Tue, Dec 13, 2011 at 8:34 PM, jbattle [jbat...@gmail.com](mailto:jbat...@gmail.com) wrote:
> 
> > Shay,
> 
> > Thank you for your response. I have done this and am no longer bound  
> > to the 1024 limit.
> 
> > Much Thanks,
> > 
> > - justin
> 
> > On Dec 13, 6:27 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > 
> > > It can only be set on the config file, not on index creation settings.  
> > > This  
> > > is because its a static setting in Lucene.
> 
> > > On Tue, Dec 13, 2011 at 1:19 AM, jbattle [jbat...@gmail.com](mailto:jbat...@gmail.com) wrote:
> > > 
> > > > I am currently setting the max\_clause\_count at the creation of my  
> > > > index as follows:
> 
> > > > "index":{  
> > > > "type" :"new",  
> > > > "bulk\_size":"100000",  
> > > > "bulk\_timeout":"1000ms",  
> > > > "query":{  
> > > > "bool":{  
> > > > "max\_clause\_count": 1000000  
> > > > }  
> > > > }  
> > > > }
> 
> > > > The setting is refelected when I check my index settings at  
> > > > [http://localhost:9200/myindex/\_settingswiththis](http://localhost:9200/myindex/_settingswiththis) line:  
> > > > index.query.bool.max\_clause\_count: "1000000"
> 
> > > > Despite this, when I run a query, I get the below error stating that  
> > > > the max\_clause\_count is the default 1024:  
> > > > Caused by: org.apache.lucene.search.BooleanQuery$TooManyClauses:  
> > > > maxClauseCount is set to 1024
> 
> > > > Any insight to why despite the setting showing the max\_clause\_count as  
> > > > set to 1000000, that Elasticsearch is still throwing that error?
> 
> > > > Thanks
> > > > 
> > > > - justin

---

<div class="post-metadata">

### Author: ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)
#### Post date: [December 14, 2011, 8:49am UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133/8 "2011-12-14T08:49:55Z")

</div>

> Is the setting being referred to in the elasticsearch yaml file?:

Yes either yaml or json. I think it should be

index:  
query:  
bool:  
max\_clause\_count: 10240

Peter.

On 14 Dez., 00:43, icenine18 [bwitha...@yahoo.com](mailto:bwitha...@yahoo.com) wrote:

> Is the setting being referred to in the elasticsearch yaml file?:
> 
> query:  
> bool:  
> max\_clause\_count: 10240
> 
> I've increased the value of this setting on my cluster, but am still  
> receiving the clause limit error using the Java API for certain  
> queries. thanks.

---

<div class="post-metadata">

### Author: ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)
#### Post date: [January 11, 2012, 10:57am UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133/9 "2012-01-11T10:57:33Z")

</div>

Following is my query that I am using :

{  
"query": {  
"bool": {  
"must": [  
{  
"text": {  
"searchable.title": {  
"type": "phrase\_prefix",  
"query": "a",  
"analyzer": "simple"  
}  
}  
}  
]  
}  
}  
}

Its being crashed when I am querying single characters as "a","b","c","v"  
etc. but not all character, like "z" is giving the response. and the  
exception in the former cases is :

_Query Failed [Failed to execute main query]]; nested: TooManyClauses[maxClauseCount is set to 1024]; }]_

So now I am trying to set the value of max\_clause\_count in the index as  
follows:

_index.query.bool.max\_clause\_count : 10240_

but the index is failing to start if the setting is there in the yml file  
and starts if I remove the setting.

So what can be the solution  
??

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [January 11, 2012, 11:03am UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133/10 "2012-01-11T11:03:06Z")

</div>

On Wed, 2012-01-11 at 02:57 -0800, Narinder Kaur wrote:

> Following is my query that I am using :
> 
> {  
> "query": {  
> "bool": {  
> "must": [  
> {  
> "text": {  
> "searchable.title": {  
> "type": "phrase\_prefix",  
> "query": "a",  
> "analyzer": "simple"  
> }  
> }  
> }  
> ]  
> }  
> }  
> }

Don't do this.

phrase\_prefix or prefix queries don't perform well when there are lots  
of matching terms.

They have to:

- load all terms beginning with $prefix
- construct a query like term\_1 OR term\_2 OR .....

So yes, if you say "give me everything beginning with 'a'" then you are  
going to have a LOT of terms, which will kill your memory and perform  
very badly.

That's why there is a limit to the number of terms/clauses. It's there  
to protect you.

The way to do this more efficiently is to analyse your text with ngrams  
or edge-ngrams.

See this email for more:  
[http://elasticsearch-users.115913.n3.nabble.com/help-needed-with-the-query-tt3177477.html#a3178856](http://elasticsearch-users.115913.n3.nabble.com/help-needed-with-the-query-tt3177477.html#a3178856)

> 

> Its being crashed when I am querying single characters as  
> "a","b","c","v" etc. but not all character, like "z" is giving the  
> response. and the exception in the former cases is :
> 
> Query Failed [Failed to execute main query]]; nested: TooManyClauses[maxClauseCount is set to 1024]; }]
> 
> So now I am trying to set the value of max\_clause\_count in the index  
> as follows:
> 
> index.query.bool.max\_clause\_count : 10240
> 
> but the index is failing to start if the setting is there in the yml  
> file and starts if I remove the setting.
> 
> So what can be the solution  
> ??

---

<div class="post-metadata">

### Author: ![Anirudh\_Modi](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@Anirudh\_Modi](https://discuss.elastic.co/u/Anirudh_Modi)
#### Post date: [February 13, 2016, 6:59am UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133/11 "2016-02-13T06:59:11Z")

</div>

Isn't there a way to continue to search even if the clause exceed, like instead of throwing an error, cant we just take the 1024 expanded clauses and continue with our search?  
I am also facing the same issue, so wanted to know if we can somehow live with this is error?

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [February 13, 2016, 9:43am UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133/12 "2016-02-13T09:43:04Z")

</div>

This is a very, very old thread. Please start a new one for you question.

---

<div class="post-metadata">

### Author: ![PeteyPabPro](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@PeteyPabPro](https://discuss.elastic.co/u/PeteyPabPro)
#### Post date: [April 14, 2016, 3:20pm UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133/13 "2016-04-14T15:20:21Z")

</div>

Did you repost this question (about whether you can just continue the search with 1024 phrases instead of getting an error)? I'm curious as well..

---

<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: [July 5, 2017, 10:59pm UTC](https://discuss.elastic.co/t/how-do-i-get-elasticsearch-max-clause-count-to-take-effect/6133/14 "2017-07-05T22:59:09Z")

</div>


