# Interesting highlighter issue

**URL:** <https://discuss.elastic.co/t/interesting-highlighter-issue/37270>\
**Category:** Elasticsearch\
**Created:** [December 15, 2015, 6:49pm UTC](https://discuss.elastic.co/t/interesting-highlighter-issue/37270 "2015-12-15T18:49:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Imran\_Azad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/imran_azad/32/4394_2.png) [@Imran\_Azad](https://discuss.elastic.co/u/Imran_Azad)\
**Post date:** [December 15, 2015, 6:49pm UTC](https://discuss.elastic.co/t/interesting-highlighter-issue/37270/1 "2015-12-15T18:49:44Z")

</div>

I am using a multi-field and I'm having an interesting issue with highlighting that I'm surprised no else has posted yet.

I have a field called `title`, within this field I have another title called `merged_title` which has an analyzer defined on it that strips hyphens and merges the word. So if I search for "anti-emetic" it highlights just on `title`because the original document text contained "anti-emetic" therefore it was tokenized individually. However in the instance where you search for "antiemetic" and the orginal document text contains "antiemetic" without a hyphen it highlights both on the `title` field and `merged_title`field. Is it possible to have it highlight only on one field in this instance?

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [December 15, 2015, 7:14pm UTC](https://discuss.elastic.co/t/interesting-highlighter-issue/37270/2 "2015-12-15T19:14:18Z")

</div>

Have a look at [matched\_fields](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html#matched-fields). I made it to solve problems like that a couple of years ago. I'm not 100% sure it covers the use case you have but its pretty close.

---

<div class="post-metadata">

**Author:** ![Imran\_Azad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/imran_azad/32/4394_2.png) [@Imran\_Azad](https://discuss.elastic.co/u/Imran_Azad)\
**Post date:** [December 15, 2015, 9:49pm UTC](https://discuss.elastic.co/t/interesting-highlighter-issue/37270/3 "2015-12-15T21:49:55Z")

</div>

Thanks Nik, wow that looks awesome just had a read of the docs and tried it out, however I'm not getting any highlights whatsoever coming back:

```
           "highlight" : {
                "fields" : {
                    "*title" : {
                        "matched_fields": ["*title", "*merge_title"],
                        "fragment_size" : 200,
                        "pre_tags" : ["<mark>"],
                        "post_tags" : ["</mark>"]
                    }
                }
            }

```

I've also set "store:yes" and term\_vector" : "with\_positions\_offsets", for both fields as I wasn't sure which field should have this option. Any ideas what I'm doing wrong? Btw my fields are heavily nested hence the wildcard characters.

Thanks

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [December 15, 2015, 10:04pm UTC](https://discuss.elastic.co/t/interesting-highlighter-issue/37270/4 "2015-12-15T22:04:19Z")

</div>

> [@Imran\_Azad](#):
>
> store:yes

Typically isn't required/actually makes things worse. Only do it after testing without it first.

> [@Imran\_Azad](#):
>
> I wasn't sure which field should have this option

Both or none are ok. Just doing it on one is likely to fail.

> [@Imran\_Azad](#):
>
> Any ideas what I'm doing wrong?

I've never tried using wildcard characters with matched\_fields. Try without the wildcards and if that works then we'll know. It just wasn't something I needed or thought about.

---

<div class="post-metadata">

**Author:** ![Imran\_Azad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/imran_azad/32/4394_2.png) [@Imran\_Azad](https://discuss.elastic.co/u/Imran_Azad)\
**Post date:** [December 15, 2015, 10:26pm UTC](https://discuss.elastic.co/t/interesting-highlighter-issue/37270/5 "2015-12-15T22:26:10Z")

</div>

Hey Nik, thanks for the swift response, you're right, the issue does seem to be with the wild cards, do I have any options for moving forward at all? I'm working an a project and I'm so close to finishing it. This is one of the last requirements, it's almost there! On a side note is it necessary to specify "\*title" twice once under "fields" and then in "matched\_fields"? It's just that I removed it from "matched\_fields" and it still worked and returned the highlighted text for \*title even though I searched explicitly in "\*merge\_title".

---

<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:** [July 5, 2017, 11:30pm UTC](https://discuss.elastic.co/t/interesting-highlighter-issue/37270/6 "2017-07-05T23:30:48Z")

</div>


