# Using FVH Highlighter and multi pre/post tags to map query string to highlight tag

**URL:** <https://discuss.elastic.co/t/using-fvh-highlighter-and-multi-pre-post-tags-to-map-query-string-to-highlight-tag/248969>\
**Category:** Elasticsearch\
**Created:** [September 17, 2020, 11:22am UTC](https://discuss.elastic.co/t/using-fvh-highlighter-and-multi-pre-post-tags-to-map-query-string-to-highlight-tag/248969 "2020-09-17T11:22:58Z")\
**Posts on this page:** 2\
**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:** [September 17, 2020, 11:22am UTC](https://discuss.elastic.co/t/using-fvh-highlighter-and-multi-pre-post-tags-to-map-query-string-to-highlight-tag/248969/1 "2020-09-17T11:22:58Z")

</div>

I am using Elasticsearch Version 7.1.1  
Given a search object like this:

```auto
{
  "query": {
    "bool": {
      "must": {
        {"query_string": {"query": "bar", "default_field": "text"},
        {"query_string": {"query": "foo", "default_field": "text"},
      }
    }
  },
  "highlight": {
    "type": "fvh",
    "pre_tags": ["<em0>", "<em1>"],
    "post_tags": ["</em0>", "</em1>"],
    "fields": {"text": {}},
  }
}

```

And a document like this:

```auto
{
  "text": "The only foo bar here is me",
}

```

I get a response with a highlight like this:

```auto
"The only <em1>foo</em1> <em0>bar</em0> here is me"

```

This example shows that the order of pre/post tags depends on the order of conditions in the query object. This is great. Clearly there are some rules here, but I can't find any reference to this logic in the docs. I have uncovered _many_ more rules like this which enabled me to hack together a parser that can read in the query object and the pre/post tags and return a map between them. I am, however, concerned that these rules may change during an update. I can elaborate on these rules if that would be helpful.

Does anyone know if these rules are explicitly written anywhere?

On a related note, it would be great if we could pass an id into the query condition, eg:

```auto
{"query_string": {"query": "bar", "default_field": "text", "tag_id": 0}}

```

Then the `tag_id` could map to the index of the related pre/post tag that should be used to highlight the matching tokens. I do understand that it's not that simple, as a query string might be composed of several tokens, some of which might be exact phrases or span conditions.

---

<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 15, 2020, 11:23am UTC](https://discuss.elastic.co/t/using-fvh-highlighter-and-multi-pre-post-tags-to-map-query-string-to-highlight-tag/248969/2 "2020-10-15T11:23:04Z")

</div>

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