# Max clause count exceeded 1024

**URL:** <https://discuss.elastic.co/t/max-clause-count-exceeded-1024/36478>\
**Category:** Elasticsearch\
**Created:** [December 6, 2015, 6:32pm UTC](https://discuss.elastic.co/t/max-clause-count-exceeded-1024/36478 "2015-12-06T18:32:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramanareddy438](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@ramanareddy438](https://discuss.elastic.co/u/ramanareddy438)\
**Post date:** [December 6, 2015, 6:32pm UTC](https://discuss.elastic.co/t/max-clause-count-exceeded-1024/36478/1 "2015-12-06T18:32:28Z")

</div>

I have more than 1024 clauses to match against a single field. If use terms query it is throwing max clauses count exceeded 1024. I thought of using bool query with multiple must terms to fetch all the documents that matches the clauses. but unfortunately that is not working. Is there any better approach to solve this problem. I am kind of dead locked if i use single terms query it is throwing max clause count 1024 exceeded error. I f use bool query with multiple must terms it is not matching any document at all.

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [December 6, 2015, 8:38pm UTC](https://discuss.elastic.co/t/max-clause-count-exceeded-1024/36478/2 "2015-12-06T20:38:32Z")

</div>

Distribute your terms in 1024 portions over several queries, iterate over the returned hits to collect total hits.

---

<div class="post-metadata">

**Author:** ![ramanareddy438](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@ramanareddy438](https://discuss.elastic.co/u/ramanareddy438)\
**Post date:** [December 7, 2015, 4:47am UTC](https://discuss.elastic.co/t/max-clause-count-exceeded-1024/36478/3 "2015-12-07T04:47:49Z")

</div>

Thank you @jprante. So there is no other way to get the results with out iterating through the portions of the data.😀

---

<div class="post-metadata">

**Author:** ![Maxim\_Valyanskiy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxim_valyanskiy/32/787_2.png) [@Maxim\_Valyanskiy](https://discuss.elastic.co/u/Maxim_Valyanskiy)\
**Post date:** [December 7, 2015, 5:37am UTC](https://discuss.elastic.co/t/max-clause-count-exceeded-1024/36478/4 "2015-12-07T05:37:58Z")

</div>

Do you really need scoring here? I think that terms query in filter position does not have 1024 clause limit.

---

<div class="post-metadata">

**Author:** ![ramanareddy438](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@ramanareddy438](https://discuss.elastic.co/u/ramanareddy438)\
**Post date:** [December 7, 2015, 5:56am UTC](https://discuss.elastic.co/t/max-clause-count-exceeded-1024/36478/5 "2015-12-07T05:56:03Z")

</div>

I am doing match on raw value (not\_analyzed) So i don't need scoring. It has to match the exact value. Looks like terms in filter position is not having 1024 clause limit. Thank @Maxim_Valyanskiy. That was really helpful.

---

<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, 11:33pm UTC](https://discuss.elastic.co/t/max-clause-count-exceeded-1024/36478/6 "2017-07-05T23:33:09Z")

</div>


