# ES "Join" making query over another query's result and aggregation

**URL:** <https://discuss.elastic.co/t/es-join-making-query-over-another-querys-result-and-aggregation/212407>\
**Category:** Elasticsearch\
**Created:** [December 18, 2019, 9:33pm UTC](https://discuss.elastic.co/t/es-join-making-query-over-another-querys-result-and-aggregation/212407 "2019-12-18T21:33:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![niztal](https://avatars.discourse-cdn.com/v4/letter/n/779978/32.png) [@niztal](https://discuss.elastic.co/u/niztal)\
**Post date:** [December 18, 2019, 9:33pm UTC](https://discuss.elastic.co/t/es-join-making-query-over-another-querys-result-and-aggregation/212407/1 "2019-12-18T21:33:40Z")

</div>

Hi all,

I have a use case where I want to have FTS (Full-Text-Search) over my corpus on ES which includes few documents over a single index.

This part is easy, but I have another index (BTW, there may be that my design of indexes is wrong, I would love to hear better design) where I set another metadata per each term in the document (e.g. term is a verb/noun/name/etc. and more..). This I do by indexing the term's index/position within the document (a.k.a "reverse index").

Now, assuming ES query's results returns some match documents, I would like also to return the metadata of processed terms.

For example:

Assuming querying the phrase "trip to London" and ES found 2 match documents (assuming ids are Doc\_1 & Doc\_2).

I would like also to return to the user these document ids and the metadata of processed query (e.g. "trip" & "london") within these two docs. For example:

Response would be by relevancy:

Doc\_1, metadatas: [{16, verb}, {22, noun}]  
Doc\_2, metadatas: [{55, name}, {88, noun}]

note: numbers above 16,22,55,88 are the terms' index within the documents.

How can I make such kind of search efficiency?

I though using the "highlighting" feature of ES but not sure it would help.

Thanks.

---

<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:** [January 15, 2020, 9:33pm UTC](https://discuss.elastic.co/t/es-join-making-query-over-another-querys-result-and-aggregation/212407/2 "2020-01-15T21:33:51Z")

</div>

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