# How highlight works?

**URL:** <https://discuss.elastic.co/t/how-highlight-works/70220>\
**Category:** Elasticsearch\
**Created:** [December 29, 2016, 3:48pm UTC](https://discuss.elastic.co/t/how-highlight-works/70220 "2016-12-29T15:48:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![geppo](https://avatars.discourse-cdn.com/v4/letter/g/3be4f8/32.png) [@geppo](https://discuss.elastic.co/u/geppo)\
**Post date:** [December 29, 2016, 3:48pm UTC](https://discuss.elastic.co/t/how-highlight-works/70220/1 "2016-12-29T15:48:13Z")

</div>

I have indicized three times the same text into a nested object to apply differents analyzers. I can't understand why if I use highlight in the query with the nested field, only for one of the nested fields works.  
with this one highlight works, changing sentences.sentence\_value to sentences.sentence\_insentitive doen't works.

```
        {
"_source": {
    "includes": ["highlight", "title", "media", "verbatim", "incrementalPushing"]
    },
    "query": {
         "bool": {
        "must": [
           {
               "match": {
                    "customer": "TSTSM"
                }
           },
           {
               "nested": {
                    "path": "sentences",
                    "query": {
                      "match_phrase": {
                        "sentences.sentence_value": {
                          "query": "commissione europea"
                        }
                      }
                    }
                  }
           }
        ]
    }
},
                         
"highlight": {
    "fields": {
        "sentences.sentence_value": {}
    }
}
}

```

Here the mapping of the nested field:

> ```
> "sentences":{ 
> "type": "nested",
> "properties": {
> "sentence_value":{
> "type": "text",
> "store": false,
> "search_analyzer": "index_analysis",
> "analyzer": "custom_italian",
> "similarity": "BM25"
> },"sentence_terms":{
> "type": "text",
> "store": true,
> "analyzer": "termvectrix",
> "similarity": "BM25"
> },
> "sentence_insensitive":{
> "type": "text",
> "store": true,
> "term_vector": "with_positions_offsets_payloads",
> "analyzer": "insensitive",
> "similarity": "BM25",
> "doc_values": true
> },
> "sentence_start":{
> "type": "date",
> "format" : "yyyy/MM/dd'-'HH:mm:ss",
> "store": false    
> },
> "sentence_end":{
> "type": "date",
> "format" : "yyyy/MM/dd'-'HH:mm:ss",
> "store": false      
> },
> "speaker_value": { 
> "type": "text",
> "index" : "not_analyzed"
> }
> }}
> 
> ```

and the anlyzers:

> ```
> "settings": {
> "analysis": {
> "filter": {
> "italian_elision": {
> "type": "elision",
> "articles": [
> "c", "l", "all", "dall", "dell",
> "nell", "sull", "coll", "pell",
> "gl", "agl", "dagl", "degl", "negl",
> "sugl", "un", "m", "t", "s", "v", "d"
> ]
> },
> "italian_stop": {
> "type": "stop",
> "stopwords": "_italian_" 
> },
> "italian_stemmer": {
> "type": "stemmer",
> "language": "light_italian"
> },
> "custom_synonym" : {
> "type" : "synonym",
> "tokenizer": "keyword",
> "synonyms_path" : "analysis/sinonimi.txt"
> },
> "edgengram":{
> "type":"edgeNGram",
> "min_gram":2,
> "max_gram":20
> },       
> "unique_stem": {
> "type": "unique",
> "only_on_same_position": true 
> }
> },
> "analyzer": {
> "termvectrix":{
> "tokenizer": "standard",
> "filter": ["standard"]},
> "custom_italian": {
> "tokenizer": "standard",
> "filter": [
> "lowercase",
> "italian_stop",
> "italian_elision",
> "keyword_repeat",
> "italian_stemmer",
> "unique_stem",
> "edgengram"
> ]
> }, "index_analysis": {"tokenizer": "standard", "filter": ["lowercase", "custom_synonym"]
> },"insensitive":{
> "tokenizer": "standard",
> "filter": [
> "lowercase"
> ]
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 30, 2016, 9:07am UTC](https://discuss.elastic.co/t/how-highlight-works/70220/2 "2016-12-30T09:07:16Z")

</div>

Hey,

please take the time and provide minimal examples, that do not contain anything else that is not related to your problem. Also ensure, that those examples can be reproduced by others. By watching those snippets here, everything pretty much boils down to either guesswork or experience by people who had the exact same problem, but noone else will be able to help.

From what I see here, you are using a different mapping in different fields, that might endup in different [highlighter implementations](https://www.elastic.co/guide/en/elasticsearch/reference/5.1/search-request-highlighting.html) being used.

In addition you should take a look at how to highlight nested documents using the [inner\_hits feature](https://www.elastic.co/guide/en/elasticsearch/reference/5.1/nested.html#_using_literal_nested_literal_fields_for_arrays_of_objects) - might be that you are after this instead.

--Alex

---

<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 27, 2017, 9:07am UTC](https://discuss.elastic.co/t/how-highlight-works/70220/3 "2017-01-27T09:07:32Z")

</div>

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