# Term Filter Lookup

**URL:** <https://discuss.elastic.co/t/term-filter-lookup/1790>\
**Category:** Elasticsearch\
**Created:** [June 3, 2015, 1:58am UTC](https://discuss.elastic.co/t/term-filter-lookup/1790 "2015-06-03T01:58:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alwin\_Augustin](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@Alwin\_Augustin](https://discuss.elastic.co/u/Alwin_Augustin)\
**Post date:** [June 3, 2015, 1:58am UTC](https://discuss.elastic.co/t/term-filter-lookup/1790/1 "2015-06-03T01:58:29Z")

</div>

I have two types called 'install' and 'events' in one index 'postbacks'. Now I need to select the event counts from events types for every day for the users who has entry in install for the particular day. Now what I am doing is, I am first fetching the ids from install for the day and using bool filter and specifying the date in must and using Ids in term . I will get around 2000 ids for a day and using it directly in should condition. So there will be 2000 terms there.

I just read about terms lookup filter. Can I use it here in this situation. I have seen in the example that we only can specify one id and path to it. But is there any possibility to use it like a subquery?

Please check the following link to see the code that I have done in PHP for this.

> <https://stackoverflow.com/questions/30599311/where-in-for-elastic-search>

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [June 3, 2015, 9:56am UTC](https://discuss.elastic.co/t/term-filter-lookup/1790/2 "2015-06-03T09:56:49Z")

</div>

You can't use a sub query, so you would have to keep running the first query on client side and then use the results to build the second query.

---

<div class="post-metadata">

**Author:** ![Alwin\_Augustin](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@Alwin\_Augustin](https://discuss.elastic.co/u/Alwin_Augustin)\
**Post date:** [June 3, 2015, 10:05am UTC](https://discuss.elastic.co/t/term-filter-lookup/1790/3 "2015-06-03T10:05:18Z")

</div>

Thanks Adrien 😄

---

<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, 12:10am UTC](https://discuss.elastic.co/t/term-filter-lookup/1790/4 "2017-07-06T00:10:01Z")

</div>


