# Highlight works not always!

**URL:** <https://discuss.elastic.co/t/highlight-works-not-always/19701>\
**Category:** Elasticsearch\
**Created:** [September 10, 2014, 7:41am UTC](https://discuss.elastic.co/t/highlight-works-not-always/19701 "2014-09-10T07:41:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramy](https://avatars.discourse-cdn.com/v4/letter/r/8491ac/32.png) [@Ramy](https://discuss.elastic.co/u/Ramy)\
**Post date:** [September 10, 2014, 7:41am UTC](https://discuss.elastic.co/t/highlight-works-not-always/19701/1 "2014-09-10T07:41:50Z")

</div>

Can someone tell me, why the highlighting works not always? what is my  
mistake?

This is my mapping:

curl -XPUT "[http://localhost:9200/my\_index](http://localhost:9200/my_index)" -d'  
{  
"settings": {  
"analysis": {  
"analyzer": {  
"autocomplete": {  
"type": "custom",  
"tokenizer": "ngram\_tokenizer",  
"filter": ["lowercase"]  
}  
},  
"tokenizer": {  
"ngram\_tokenizer": {  
"type": "ngram",  
"min\_gram": 1,  
"max\_gram": 20,  
"token\_chars": ["letter", "digit"]  
}  
}  
}  
},  
...  
}'

and here is my query:

curl -XGET "[http://localhost:9200/my\_index/my\_type/\_search](http://localhost:9200/my_index/my_type/_search)" -d'  
{  
"\_source": false,  
"size": 5,  
"query": {  
"multi\_match": {  
"query": "_tisch_",  
"fields": [  
"_\_de.autocomplete"  
],  
"operator": "and"  
}  
},  
"highlight": {  
"pre\_tags": [  
"**"  
],  
"post\_tags": [  
"**"  
],  
"fields": {  
"_\_de.autocomplete": {}  
}  
}  
}'

and this is my result:

{  
"took": 220,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 3649,  
"max\_score": 0.88375586,  
"hits": [  
{  
"\_index": "my\_index",  
"\_type": "my\_type",  
"\_id": "1",  
"\_score": 0.88375586,  
"highlight": {  
"group\_name\_3\_de.autocomplete": [  
"Konsol_tisch_e",  
"Garten-Ess **_tisch_** e"  
],  
"group\_name\_2\_de.autocomplete": [  
" **_Tisch_** e",  
"Gartentische"  
]  
}  
},  
{  
"\_index": "architonic",  
"\_type": "product",  
"\_id": "2",  
"\_score": 0.88375586,  
"highlight": {  
"group\_name\_3\_de.autocomplete": [  
"Schreib_tisch_e",  
"Ess **_tisch_** e"  
],  
"group\_name\_2\_de.autocomplete": [  
" **_Tisch_** e"  
]  
}  
},  
{  
"\_index": "architonic",  
"\_type": "product",  
"\_id": "3",  
"\_score": 0.88375586,  
"highlight": {  
"group\_name\_3\_de.autocomplete": [  
"Einzel_tisch_e"  
],  
"group\_name\_2\_de.autocomplete": [  
"Büro **_tisch_** e"  
]  
}  
},  
...  
]  
}  
}

As you can see. Elasticsearch was able to highlight some words. I marked  
them as _pink_ and the other are marked as _red_

Where is the failure?

Thank you

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e72c34b1-be77-433b-8120-9c3c51af3186%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e72c34b1-be77-433b-8120-9c3c51af3186%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [September 10, 2014, 11:30am UTC](https://discuss.elastic.co/t/highlight-works-not-always/19701/2 "2014-09-10T11:30:42Z")

</div>

Hello Ramy ,

Can you show the mapping ( not just the index creation JSON).  
I need to make sure you have applied ngram on the required field.

Thanks  
Vineeth

On Wed, Sep 10, 2014 at 1:11 PM, Ramy [remram78@gmail.com](mailto:remram78@gmail.com) wrote:

> Can someone tell me, why the highlighting works not always? what is my  
> mistake?
> 
> This is my mapping:
> 
> curl -XPUT "[http://localhost:9200/my\_index](http://localhost:9200/my_index)" -d'  
> {  
> "settings": {  
> "analysis": {  
> "analyzer": {  
> "autocomplete": {  
> "type": "custom",  
> "tokenizer": "ngram\_tokenizer",  
> "filter": ["lowercase"]  
> }  
> },  
> "tokenizer": {  
> "ngram\_tokenizer": {  
> "type": "ngram",  
> "min\_gram": 1,  
> "max\_gram": 20,  
> "token\_chars": ["letter", "digit"]  
> }  
> }  
> }  
> },  
> ...  
> }'
> 
> and here is my query:
> 
> curl -XGET "[http://localhost:9200/my\_index/my\_type/\_search](http://localhost:9200/my_index/my_type/_search)" -d'  
> {  
> "\_source": false,  
> "size": 5,  
> "query": {  
> "multi\_match": {  
> "query": "_tisch_",  
> "fields": [  
> "_\_de.autocomplete"  
> ],  
> "operator": "and"  
> }  
> },  
> "highlight": {  
> "pre\_tags": [  
> "**"  
> ],  
> "post\_tags": [  
> "**"  
> ],  
> "fields": {  
> "_\_de.autocomplete": {}  
> }  
> }  
> }'
> 
> and this is my result:
> 
> {  
> "took": 220,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "hits": {  
> "total": 3649,  
> "max\_score": 0.88375586,  
> "hits": [  
> {  
> "\_index": "my\_index",  
> "\_type": "my\_type",  
> "\_id": "1",  
> "\_score": 0.88375586,  
> "highlight": {  
> "group\_name\_3\_de.autocomplete": [  
> "Konsol_tisch_e",  
> "Garten-Ess **_tisch_** e"  
> ],  
> "group\_name\_2\_de.autocomplete": [  
> " **_Tisch_** e",  
> "Gartentische"  
> ]  
> }  
> },  
> {  
> "\_index": "architonic",  
> "\_type": "product",  
> "\_id": "2",  
> "\_score": 0.88375586,  
> "highlight": {  
> "group\_name\_3\_de.autocomplete": [  
> "Schreib_tisch_e",  
> "Ess **_tisch_** e"  
> ],  
> "group\_name\_2\_de.autocomplete": [  
> " **_Tisch_** e"  
> ]  
> }  
> },  
> {  
> "\_index": "architonic",  
> "\_type": "product",  
> "\_id": "3",  
> "\_score": 0.88375586,  
> "highlight": {  
> "group\_name\_3\_de.autocomplete": [  
> "Einzel_tisch_e"  
> ],  
> "group\_name\_2\_de.autocomplete": [  
> "Büro **_tisch_** e"  
> ]  
> }  
> },  
> ...  
> ]  
> }  
> }
> 
> As you can see. Elasticsearch was able to highlight some words. I marked  
> them as _pink_ and the other are marked as _red_
> 
> Where is the failure?
> 
> Thank you
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/e72c34b1-be77-433b-8120-9c3c51af3186%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e72c34b1-be77-433b-8120-9c3c51af3186%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/e72c34b1-be77-433b-8120-9c3c51af3186%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/e72c34b1-be77-433b-8120-9c3c51af3186%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k%2BJ0oNgF%3DefUcAqZhC6mrZM601DaSYhTggv1xJJGxBKg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k%2BJ0oNgF%3DefUcAqZhC6mrZM601DaSYhTggv1xJJGxBKg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:03am UTC](https://discuss.elastic.co/t/highlight-works-not-always/19701/3 "2017-07-06T01:03:22Z")

</div>


