# Terms lookup based on ids matching query

**URL:** <https://discuss.elastic.co/t/terms-lookup-based-on-ids-matching-query/125514>\
**Category:** Elasticsearch\
**Created:** [March 25, 2018, 8:45pm UTC](https://discuss.elastic.co/t/terms-lookup-based-on-ids-matching-query/125514 "2018-03-25T20:45:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Lam](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@Patrick\_Lam](https://discuss.elastic.co/u/Patrick_Lam)\
**Post date:** [March 25, 2018, 8:45pm UTC](https://discuss.elastic.co/t/terms-lookup-based-on-ids-matching-query/125514/1 "2018-03-25T20:45:59Z")

</div>

Hi,

I'm looking for something similar to the terms lookup filter but slightly different. Let's assume that I have two indexes. One is an index of tweets with the user ID as a field. The other is a list of user profiles with user specific info (let's say hypothetically gender is one of the fields).

Currently, the terms lookup filter is able to take an array within a single document in the users index and match to the tweet index. So if I have a list of followers of a specific user as an array, I can retrieve all the tweets matching any of the followers.

What I'm looking for is actually whether I can make a query on the users index, find all user IDs that match that query, and then retrieve all tweets matching any of the users in the original query. So assume I want to retrieve all tweets from gender:male. Can I make a match query for gender:male in the users index, get all the user IDs, and then find all tweets from those user IDs using a terms filter for those IDs all within a single step?

I know I can do this with a parent/child relationship format, but is there a way to do this without indexing in that way that is akin to the terms lookup filter?

---

<div class="post-metadata">

**Author:** ![ddorian43](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddorian43/32/36093_2.png) [@ddorian43](https://discuss.elastic.co/u/ddorian43)\
**Post date:** [March 25, 2018, 11:02pm UTC](https://discuss.elastic.co/t/terms-lookup-based-on-ids-matching-query/125514/2 "2018-03-25T23:02:34Z")

</div>

no, cause that would be a distributed join

there is an commercial plugin `siren vanguard` 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:** [April 22, 2018, 11:02pm UTC](https://discuss.elastic.co/t/terms-lookup-based-on-ids-matching-query/125514/3 "2018-04-22T23:02:41Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
