# Max (recommended) number of values for "terms" search

**URL:** <https://discuss.elastic.co/t/max-recommended-number-of-values-for-terms-search/6365>\
**Category:** Elasticsearch\
**Created:** [January 12, 2012, 5:39pm UTC](https://discuss.elastic.co/t/max-recommended-number-of-values-for-terms-search/6365 "2012-01-12T17:39:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ittai\_Zeidman](https://avatars.discourse-cdn.com/v4/letter/i/838e76/32.png) [@Ittai\_Zeidman](https://discuss.elastic.co/u/Ittai_Zeidman)\
**Post date:** [January 12, 2012, 5:39pm UTC](https://discuss.elastic.co/t/max-recommended-number-of-values-for-terms-search/6365/1 "2012-01-12T17:39:58Z")

</div>

Hi,  
I have a need for a kind of "join" with immediate indexing and so I want to  
keep the end of the relationship which is not searchable in my RDBMS and  
query first the RDBMS get the list of ids for that entity which are  
applicable and then use the "terms" search as one of the parameter when  
querying my heavy-load document (which of course has an otherEntity\_id  
field on it).  
My question is what is a rough upper bound of the number of values I can  
put in the "terms" search ("in" clause) for a specific string field?

Thanks,  
Ittai

---

<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:** [January 12, 2012, 11:15pm UTC](https://discuss.elastic.co/t/max-recommended-number-of-values-for-terms-search/6365/2 "2012-01-12T23:15:29Z")

</div>

There isn't really a limit, but the more you have, the slower it will be.  
The way the terms filter work is by iterating over all the terms and  
building an bitset of the docs matching. The result is cached so if you use  
the same set of ids again, you will get fast response.

One way to improve that is to actually build a bool filter composed of  
single term filter (which are cached automatically individually), so each  
id will have its own cached result. This can become quite expressive though  
in terms of building the filter, thats why there is an improvement in  
master to allow for "execution" mode in terms filter, see more here:  
[Query DSL: Add different execution models for terms filter · Issue #1568 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1568).

On Thu, Jan 12, 2012 at 7:39 PM, Ittai Zeidman [ittai@fashion-traffic.com](mailto:ittai@fashion-traffic.com)wrote:

> Hi,  
> I have a need for a kind of "join" with immediate indexing and so I want  
> to keep the end of the relationship which is not searchable in my RDBMS and  
> query first the RDBMS get the list of ids for that entity which are  
> applicable and then use the "terms" search as one of the parameter when  
> querying my heavy-load document (which of course has an otherEntity\_id  
> field on it).  
> My question is what is a rough upper bound of the number of values I can  
> put in the "terms" search ("in" clause) for a specific string field?
> 
> Thanks,  
> Ittai

---

<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 6, 2017, 3:42am UTC](https://discuss.elastic.co/t/max-recommended-number-of-values-for-terms-search/6365/3 "2017-07-06T03:42:53Z")

</div>

Closed on July 6, 2017, 3:42am UTC


