# Mapping the query to the highlight using FVH

**URL:** <https://discuss.elastic.co/t/mapping-the-query-to-the-highlight-using-fvh/257836>\
**Category:** Elasticsearch\
**Created:** [December 7, 2020, 11:02am UTC](https://discuss.elastic.co/t/mapping-the-query-to-the-highlight-using-fvh/257836 "2020-12-07T11:02:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackhodkinson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jackhodkinson/32/75779_2.png) [@jackhodkinson](https://discuss.elastic.co/u/jackhodkinson)\
**Post date:** [December 7, 2020, 11:02am UTC](https://discuss.elastic.co/t/mapping-the-query-to-the-highlight-using-fvh/257836/1 "2020-12-07T11:02:13Z")

</div>

The highlighters are great because they help you figure out why your query matched a document. Unfortunately when they are used in conjuncture with any kind of analyzer that stems the words in the query, it is difficult to figure out WHY the query matches a document. The FVH highlighter and the pre/post tags help a bit, but it is not clear from the docs what the expected behavior of the FVH highlighter is.

I wrote [a post](https://discuss.elastic.co/t/using-fvh-highlighter-and-multi-pre-post-tags-to-map-query-string-to-highlight-tag/248969) a while ago about about the topic but got no discussion going. So I've written a longer deep dive about the subject here.

[https://jack-hodkinson.medium.com/reverse-engineering-elasticsearch-highlights-e36ec4164e84](https://jack-hodkinson.medium.com/reverse-engineering-elasticsearch-highlights-e36ec4164e84)

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [December 7, 2020, 2:14pm UTC](https://discuss.elastic.co/t/mapping-the-query-to-the-highlight-using-fvh/257836/2 "2020-12-07T14:14:32Z")

</div>

Thanks for the write-up.  
One approach for more transparency into what search terms matched might be to use the highlighter that ships with the [annotated\_text](https://www.elastic.co/blog/search-for-things-not-strings-with-the-annotated-text-plugin) field which is installed as an extra [plugin](https://www.elastic.co/guide/en/elasticsearch/plugins/7.10/mapper-annotated-text.html). Although it's designed for use on `annotated_text` fields it also works with `text` fields and uses a markdown-like syntax for adding annotations to text e.g. given this doc:

```auto
{
	"text": "The new hot technology has emerged!"
}

```

and this query

```auto
{
	"query": {
		"bool": {
			"should": [
				{"match": {"text": "fabulous"}},
				{"match": {"text": "new"}}
			],
			"must": [
				{"match": {"text": "technology"}},
				{"wildcard": {"text": "emerg*"}}
			]
		}
	},
	"highlight": {
		"type": "annotated",
		"fields": {
			"text": {}
		}
	}
}

```

The marked-up result includes which terms matched a section of text:

```auto
        "highlight": {
          "text": [
            "The [new](_hit_term=new) hot [technology](_hit_term=technology) has [emerged](_hit_term=text%3Aemerg*)!"
          ]
        }

```

---

<div class="post-metadata">

**Author:** ![jackhodkinson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jackhodkinson/32/75779_2.png) [@jackhodkinson](https://discuss.elastic.co/u/jackhodkinson)\
**Post date:** [December 7, 2020, 2:35pm UTC](https://discuss.elastic.co/t/mapping-the-query-to-the-highlight-using-fvh/257836/3 "2020-12-07T14:35:03Z")

</div>

That could be a nice solution. I've been meaning to try out annotated text too. I'll give it a go. 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 4, 2021, 2:35pm UTC](https://discuss.elastic.co/t/mapping-the-query-to-the-highlight-using-fvh/257836/4 "2021-01-04T14:35:07Z")

</div>

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