# Return matching analyzed field when querying

**URL:** <https://discuss.elastic.co/t/return-matching-analyzed-field-when-querying/215889>\
**Category:** Elasticsearch\
**Created:** [January 21, 2020, 1:46pm UTC](https://discuss.elastic.co/t/return-matching-analyzed-field-when-querying/215889 "2020-01-21T13:46:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nogias](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nogias/32/61134_2.png) [@nogias](https://discuss.elastic.co/u/nogias)\
**Post date:** [January 21, 2020, 1:46pm UTC](https://discuss.elastic.co/t/return-matching-analyzed-field-when-querying/215889/1 "2020-01-21T13:46:58Z")

</div>

Hi everybody,

**Context:**  
My real product is a bit complex, so I'm explaining it as blog post, then.  
I have blog posts which are stored in ES.  
I have an analyzer to analyze posts' content into tokens. The analyzer will be changed and might become more complex as the product grows up.

Everytime a user search for posts, say he's searching "multi thread programming java", I would like to know which analyzed tokens (token, start\_offset, end\_offset) of field "post.content.analyzed\_my\_way" match user's search string, So that I can make these words bold (like Google search).  
This field ideally should be return along with each hits when request ES query.

**Problems:**

1. "post.content.analyzed\_my\_way" is not stored by default, so it's not returned through "store\_fields". Is it a good practice to store the analyzed field?

2. Logic of the analyzer is complex and will be changed often, so I cannot mimic it outside of ES. That violates DRY, too.

3. Calling POST /post/\_analyze to analyze a content on fly doesn't seems a good choice, because it repeats the task of querying (ES already analyzed/indexed post documents).  
GET /post/\_doc/post-id/\_termvectors seems a bit better but still not solve my #4 problem.

4. While querying, ES doesn't return position of matching token in it explanations

5. If "post.content" becomes "post.contents" (array), #3 solution doesn't point out which content a analyzed token belong to.

Any helps will be helpful and appreciated.  
Thank you for reading.

---

<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:** [February 18, 2020, 1:47pm UTC](https://discuss.elastic.co/t/return-matching-analyzed-field-when-querying/215889/2 "2020-02-18T13:47:00Z")

</div>

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