# Terms lookup mechanism - in reverse?

**URL:** <https://discuss.elastic.co/t/terms-lookup-mechanism-in-reverse/95572>\
**Category:** Elasticsearch\
**Created:** [August 2, 2017, 3:48pm UTC](https://discuss.elastic.co/t/terms-lookup-mechanism-in-reverse/95572 "2017-08-02T15:48:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisburrell](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@chrisburrell](https://discuss.elastic.co/u/chrisburrell)\
**Post date:** [August 2, 2017, 3:48pm UTC](https://discuss.elastic.co/t/terms-lookup-mechanism-in-reverse/95572/1 "2017-08-02T15:48:19Z")

</div>

Hi

My understanding of the terms lookup mechanism is that you can provide a term and then as a result of that surface the documents that match a particular term name. So for example if you had an User and a Transaction, you could lookup the user's name and surface his transactions.

However, if I wanted to surface all user's names across all transactions, I'm assuming that wouldn't be possible with this mechanism. i.e. a table that has both the user name and its transactions.

From reading the docs, I'm assuming that's where nesting/child-parent relationships comes in.

Thanks  
Chris

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [August 2, 2017, 7:37pm UTC](https://discuss.elastic.co/t/terms-lookup-mechanism-in-reverse/95572/2 "2017-08-02T19:37:55Z")

</div>

Terms lookup is just fetching a list of terms from a static document, and then using those values as the list of terms to filter by. So it isn't really any different from providing the list yourself, except it resides inside a document which can sometimes be easier to deal with (for "persistent" lists, long lists, etc).

If you just want a list of all users that had a transaction, you could do something like a `terms` aggregation on the username field... that'll give you a list of distinct terms (usernames) in the index.

---

<div class="post-metadata">

**Author:** ![chrisburrell](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@chrisburrell](https://discuss.elastic.co/u/chrisburrell)\
**Post date:** [August 3, 2017, 8:00am UTC](https://discuss.elastic.co/t/terms-lookup-mechanism-in-reverse/95572/3 "2017-08-03T08:00:58Z")

</div>

Thank @polyfractal. What I was after is something like:

| username | transaction |  
| u1 | t1 |  
| u2 | t2 |  
| u1 | t3 |

But what you say confirms my understanding.

Cheers  
Chris

---

<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:** [August 31, 2017, 8:01am UTC](https://discuss.elastic.co/t/terms-lookup-mechanism-in-reverse/95572/4 "2017-08-31T08:01:10Z")

</div>

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