# How many clauses can go in a bool filter by default?

**URL:** <https://discuss.elastic.co/t/how-many-clauses-can-go-in-a-bool-filter-by-default/62732>\
**Category:** Elasticsearch\
**Created:** [October 11, 2016, 3:50pm UTC](https://discuss.elastic.co/t/how-many-clauses-can-go-in-a-bool-filter-by-default/62732 "2016-10-11T15:50:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![afaraone](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@afaraone](https://discuss.elastic.co/u/afaraone)\
**Post date:** [October 11, 2016, 3:50pm UTC](https://discuss.elastic.co/t/how-many-clauses-can-go-in-a-bool-filter-by-default/62732/1 "2016-10-11T15:50:31Z")

</div>

^ Trying to track down a bug and i think it's related. I have a query that may be creating up to 2200 clauses within the "should" block of a bool query.

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [October 11, 2016, 3:57pm UTC](https://discuss.elastic.co/t/how-many-clauses-can-go-in-a-bool-filter-by-default/62732/2 "2016-10-11T15:57:12Z")

</div>

I think the default maximum clause count for lucene BooleanQuery is 1024, but theres the `indices.query.bool.max_clause_count` setting where you can increase this:

[http://george-stathis.com/2013/10/18/setting-the-booleanquery-maxclausecount-in-elasticsearch](http://george-stathis.com/2013/10/18/setting-the-booleanquery-maxclausecount-in-elasticsearch)

However be sure to measure the impact that queries of that size can have on your cluster.

---

<div class="post-metadata">

**Author:** ![afaraone](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@afaraone](https://discuss.elastic.co/u/afaraone)\
**Post date:** [October 11, 2016, 4:05pm UTC](https://discuss.elastic.co/t/how-many-clauses-can-go-in-a-bool-filter-by-default/62732/3 "2016-10-11T16:05:23Z")

</div>

are there best practices for setting this value? or a known point at which it becomes an issue because the query is too long?

That said, is there a cap on the length of queries? what is that value, if so?

many thanks, sorry for the machine gun questions!

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [October 11, 2016, 5:42pm UTC](https://discuss.elastic.co/t/how-many-clauses-can-go-in-a-bool-filter-by-default/62732/4 "2016-10-11T17:42:06Z")

</div>

Great question,

I have a feeling this limit is more a kind of safeguard for people to not shoot themselves in the foot by accidentaly adding too much clauses (or users DOSing your search engine by querying for gazillions of terms) or creating overly complicated queries to begin with. These queries will probably be slower, but I this also depends on the kind of data you have. The right limit also seems to be debated in the Lucene community itself when you look at their [discussions](https://issues.apache.org/jira/browse/LUCENE-4835).  
So I get the feeling that increasing the limit by - say a factor of 10x - should not be problematic although your queries might get slower. I'd be interested in other peoples opinions about this though.

---

<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:13pm UTC](https://discuss.elastic.co/t/how-many-clauses-can-go-in-a-bool-filter-by-default/62732/5 "2017-07-05T22:13:21Z")

</div>


