# Terms queries with lots of terms

**URL:** <https://discuss.elastic.co/t/terms-queries-with-lots-of-terms/45193>\
**Category:** Elasticsearch\
**Created:** [March 23, 2016, 8:53am UTC](https://discuss.elastic.co/t/terms-queries-with-lots-of-terms/45193 "2016-03-23T08:53:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xam](https://avatars.discourse-cdn.com/v4/letter/x/bb73d2/32.png) [@xam](https://discuss.elastic.co/u/xam)\
**Post date:** [March 23, 2016, 8:53am UTC](https://discuss.elastic.co/t/terms-queries-with-lots-of-terms/45193/1 "2016-03-23T08:53:09Z")

</div>

Hi all,

I use the following request to perform a terms query with many terms:  
{  
"query" : {  
"terms" : {  
"users" : {  
"index" : "termset",  
"type" : "termset",  
"id" : "TERMSET1",  
"path" : "terms"  
}  
}  
}  
}

As my TERMSET1 is very big, I hit the maxbooleanclauses exception.  
I tried to switch to "filter context", but then I get the exception "org.elasticsearch.index.query.QueryParsingException: request does not support [filter]".

Is the only way to perform a query using a big term set is to increase the maxbooleanclauses limit?

Thank you,

---

<div class="post-metadata">

**Author:** ![danstaines](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danstaines/32/9052_2.png) [@danstaines](https://discuss.elastic.co/u/danstaines)\
**Post date:** [April 12, 2016, 10:50am UTC](https://discuss.elastic.co/t/terms-queries-with-lots-of-terms/45193/2 "2016-04-12T10:50:22Z")

</div>

Working with ES 2.2.0, I got round this problem with \>50,000 IDs or terms by wrapping my query in a ConstantScoreQuery ie.  
{  
"constant\_score" : {  
"filter" : {  
"ids" : {...)  
}  
}  
see:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html)

This stopped the maxbooleanclauses problem BUT I now see very poor performance when retrieving the whole set using scrolling, but haven't yet found a solution.

---

<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:00pm UTC](https://discuss.elastic.co/t/terms-queries-with-lots-of-terms/45193/3 "2017-07-05T23:00:13Z")

</div>


