# Terms Query - Return matched term with hit?

**URL:** <https://discuss.elastic.co/t/terms-query-return-matched-term-with-hit/102345>\
**Category:** Elasticsearch\
**Created:** [September 30, 2017, 12:29pm UTC](https://discuss.elastic.co/t/terms-query-return-matched-term-with-hit/102345 "2017-09-30T12:29:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DefensiveDepth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/defensivedepth/32/110034_2.png) [@DefensiveDepth](https://discuss.elastic.co/u/DefensiveDepth)\
**Post date:** [September 30, 2017, 12:29pm UTC](https://discuss.elastic.co/t/terms-query-return-matched-term-with-hit/102345/1 "2017-09-30T12:29:51Z")

</div>

I am using the Terms query with a document lookup to load the Terms.

Is there a way to return the specific term that was found with each hit? Right now, all I get back is a list of hits, but I don't know which terms were found in which hit.

Thanks,

---

<div class="post-metadata">

**Author:** ![toka](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/toka/32/15773_2.png) [@toka](https://discuss.elastic.co/u/toka)\
**Post date:** [October 2, 2017, 7:12am UTC](https://discuss.elastic.co/t/terms-query-return-matched-term-with-hit/102345/2 "2017-10-02T07:12:32Z")

</div>

From a practical point of view, a lookup is just like a normal `Terms query`, so, I'm not sure, but I don't think there's a way to get that information in the response.

You'd have to do that check manually, comparing the result with your original terms list.

---

<div class="post-metadata">

**Author:** ![DefensiveDepth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/defensivedepth/32/110034_2.png) [@DefensiveDepth](https://discuss.elastic.co/u/DefensiveDepth)\
**Post date:** [October 2, 2017, 3:59pm UTC](https://discuss.elastic.co/t/terms-query-return-matched-term-with-hit/102345/3 "2017-10-02T15:59:03Z")

</div>

Tried some other things...

Using the highlight function, I can get a result back that tags the found term.... Then I just strip out the highlight tags and I am good to go.. A little hacky, but it will work for the project.

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:** [October 30, 2017, 3:59pm UTC](https://discuss.elastic.co/t/terms-query-return-matched-term-with-hit/102345/4 "2017-10-30T15:59:14Z")

</div>

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