# Highlighting is not working

**URL:** <https://discuss.elastic.co/t/highlighting-is-not-working/20955>\
**Category:** Elasticsearch\
**Created:** [November 26, 2014, 4:26pm UTC](https://discuss.elastic.co/t/highlighting-is-not-working/20955 "2014-11-26T16:26:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepak\_Mehta](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@Deepak\_Mehta](https://discuss.elastic.co/u/Deepak_Mehta)\
**Post date:** [November 26, 2014, 4:26pm UTC](https://discuss.elastic.co/t/highlighting-is-not-working/20955/1 "2014-11-26T16:26:55Z")

</div>

I am using Elastic Search 1.3.5.  
I have fields like filename, foldername and content. In query I am trying  
to highlight matched content.

In Query if keyword only matches in content then keyword is highlighted and  
its becoming bold. However if keyword matches in (filename or foldername)  
and content then content is not highlighted.  
What I am missing here?

Query sample,

{  
"query": {  
"filtered": {  
"query": {  
"bool": {  
"should": [  
{  
"match": {  
"fileName": {  
"query": "document",  
"boost": 4  
}  
}  
},  
{  
"match": {  
"folderName": {  
"query": "document",  
"boost": 3  
}  
}  
},  
{  
"match": {  
"fileName.trigram": {  
"query": "document",  
"boost": 2,  
"minimum\_should\_match": "50%"  
}  
}  
},  
{  
"match": {  
"content": {  
"query": "document",  
"boost": 5  
}  
}  
},  
{  
"match": {  
"folderName.trigram": {  
"query": "document",  
"boost": 1,  
"minimum\_should\_match": "50%"  
}  
}  
}  
]  
}  
},  
"filter": {  
"and": [  
{  
"term": {  
"businessId": 1  
}  
},  
{  
"term": {  
"deleted": false  
}  
},  
{  
"bool": {  
"should": [  
{  
"term": {  
"folderPath": "/shared/documents"  
}  
},  
{  
"prefix": {  
"folderPath": "/shared/documents/"  
}  
}  
]  
}  
}  
]  
}  
}  
},  
"highlight": {  
"fields": {  
"content": {  
"fragment\_size": 150,  
"number\_of\_fragments": 0,  
"no\_match\_size": 150  
}  
},  
"pre\_tags": [  
""  
],  
"post\_tags": [  
""  
]  
}  
}

--  
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/5fffefc1-c2f3-4b2d-aa64-b804da6dc3ff%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5fffefc1-c2f3-4b2d-aa64-b804da6dc3ff%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [November 26, 2014, 4:29pm UTC](https://discuss.elastic.co/t/highlighting-is-not-working/20955/2 "2014-11-26T16:29:11Z")

</div>

Can you post an example document? Can you post your mapping? Mapping is  
important because depending on how your mapping is set up you'll get a  
totally different highlighter implementation.

Nik

On Wed, Nov 26, 2014 at 11:26 AM, Deepak Mehta [hopelight.l@gmail.com](mailto:hopelight.l@gmail.com)  
wrote:

> I am using Elastic Search 1.3.5.  
> I have fields like filename, foldername and content. In query I am trying  
> to highlight matched content.
> 
> In Query if keyword only matches in content then keyword is highlighted  
> and its becoming bold. However if keyword matches in (filename or  
> foldername) and content then content is not highlighted.  
> What I am missing here?
> 
> Query sample,
> 
> {  
> "query": {  
> "filtered": {  
> "query": {  
> "bool": {  
> "should": [  
> {  
> "match": {  
> "fileName": {  
> "query": "document",  
> "boost": 4  
> }  
> }  
> },  
> {  
> "match": {  
> "folderName": {  
> "query": "document",  
> "boost": 3  
> }  
> }  
> },  
> {  
> "match": {  
> "fileName.trigram": {  
> "query": "document",  
> "boost": 2,  
> "minimum\_should\_match": "50%"  
> }  
> }  
> },  
> {  
> "match": {  
> "content": {  
> "query": "document",  
> "boost": 5  
> }  
> }  
> },  
> {  
> "match": {  
> "folderName.trigram": {  
> "query": "document",  
> "boost": 1,  
> "minimum\_should\_match": "50%"  
> }  
> }  
> }  
> ]  
> }  
> },  
> "filter": {  
> "and": [  
> {  
> "term": {  
> "businessId": 1  
> }  
> },  
> {  
> "term": {  
> "deleted": false  
> }  
> },  
> {  
> "bool": {  
> "should": [  
> {  
> "term": {  
> "folderPath": "/shared/documents"  
> }  
> },  
> {  
> "prefix": {  
> "folderPath": "/shared/documents/"  
> }  
> }  
> ]  
> }  
> }  
> ]  
> }  
> }  
> },  
> "highlight": {  
> "fields": {  
> "content": {  
> "fragment\_size": 150,  
> "number\_of\_fragments": 0,  
> "no\_match\_size": 150  
> }  
> },  
> "pre\_tags": [  
> ""  
> ],  
> "post\_tags": [  
> ""  
> ]  
> }  
> }
> 
> --  
> 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/5fffefc1-c2f3-4b2d-aa64-b804da6dc3ff%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5fffefc1-c2f3-4b2d-aa64-b804da6dc3ff%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/5fffefc1-c2f3-4b2d-aa64-b804da6dc3ff%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/5fffefc1-c2f3-4b2d-aa64-b804da6dc3ff%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/CAPmjWd10Depf6q5cdsAfpkd-cbdYtimGhCfkeX4SKU2JFXYZXg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd10Depf6q5cdsAfpkd-cbdYtimGhCfkeX4SKU2JFXYZXg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Deepak\_Mehta](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@Deepak\_Mehta](https://discuss.elastic.co/u/Deepak_Mehta)\
**Post date:** [November 27, 2014, 5:47am UTC](https://discuss.elastic.co/t/highlighting-is-not-working/20955/3 "2014-11-27T05:47:29Z")

</div>

Document looks like this,

{  
"\_index": "mdb-pod1-1",  
"\_type": "file",  
"\_id": "81f87ac0-8362-43f0-bdf2-485d109bed18",  
"\_score": 1,  
"\_source": {  
"fileName": "documents.txt",  
"fileExtension": "txt",  
"pid": 1,  
"folderName": "Documents",  
"trash": false,  
"content": "This is fine and documents are working fine.\n\n"  
}  
}

Mapping looks like this,

"fileName": {  
"type": "multi\_field",  
"fields": {  
"fileName": {  
"type": "string",  
"analyzer": "generic\_name\_analyzer"  
},  
"trigram": {  
"type": "string",  
"analyzer": "trigram\_name\_analyzer"  
}  
}  
},  
"folderName": {  
"type": "multi\_field",  
"fields": {  
"folderName": {  
"type": "string",  
"analyzer": "generic\_name\_analyzer"  
},  
"trigram": {  
"type": "string",  
"analyzer": "trigram\_name\_analyzer"  
}  
}  
},  
"content": {  
"type": "string",  
"analyzer": "generic\_text\_analyzer"  
},

"analyzer": {  
"generic\_name\_analyzer": {  
"filter": [  
"subword\_split",  
"extension\_split",  
"icu\_folding",  
"english\_stop"  
],  
"type": "custom",  
"tokenizer": "icu\_tokenizer"  
},  
"generic\_text\_analyzer": {  
"filter": [  
"subword\_split",  
"icu\_folding",  
"english\_stop",  
"max\_token\_limit"  
],  
"type": "custom",  
"tokenizer": "icu\_tokenizer"  
},  
"trigram\_name\_analyzer": {  
"filter": [  
"icu\_folding",  
"trigram\_filter"  
],  
"type": "custom",  
"tokenizer": "icu\_tokenizer"  
}  
}

On Wednesday, November 26, 2014 9:59:55 PM UTC+5:30, Nikolas Everett wrote:

> Can you post an example document? Can you post your mapping? Mapping is  
> important because depending on how your mapping is set up you'll get a  
> totally different highlighter implementation.
> 
> Nik
> 
> On Wed, Nov 26, 2014 at 11:26 AM, Deepak Mehta \<[hopel...@gmail.com](mailto:hopel...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > I am using Elastic Search 1.3.5.  
> > I have fields like filename, foldername and content. In query I am trying  
> > to highlight matched content.
> > 
> > In Query if keyword only matches in content then keyword is highlighted  
> > and its becoming bold. However if keyword matches in (filename or  
> > foldername) and content then content is not highlighted.  
> > What I am missing here?
> > 
> > Query sample,
> > 
> > {  
> > "query": {  
> > "filtered": {  
> > "query": {  
> > "bool": {  
> > "should": [  
> > {  
> > "match": {  
> > "fileName": {  
> > "query": "document",  
> > "boost": 4  
> > }  
> > }  
> > },  
> > {  
> > "match": {  
> > "folderName": {  
> > "query": "document",  
> > "boost": 3  
> > }  
> > }  
> > },  
> > {  
> > "match": {  
> > "fileName.trigram": {  
> > "query": "document",  
> > "boost": 2,  
> > "minimum\_should\_match": "50%"  
> > }  
> > }  
> > },  
> > {  
> > "match": {  
> > "content": {  
> > "query": "document",  
> > "boost": 5  
> > }  
> > }  
> > },  
> > {  
> > "match": {  
> > "folderName.trigram": {  
> > "query": "document",  
> > "boost": 1,  
> > "minimum\_should\_match": "50%"  
> > }  
> > }  
> > }  
> > ]  
> > }  
> > },  
> > "filter": {  
> > "and": [  
> > {  
> > "term": {  
> > "businessId": 1  
> > }  
> > },  
> > {  
> > "term": {  
> > "deleted": false  
> > }  
> > },  
> > {  
> > "bool": {  
> > "should": [  
> > {  
> > "term": {  
> > "folderPath": "/shared/documents"  
> > }  
> > },  
> > {  
> > "prefix": {  
> > "folderPath": "/shared/documents/"  
> > }  
> > }  
> > ]  
> > }  
> > }  
> > ]  
> > }  
> > }  
> > },  
> > "highlight": {  
> > "fields": {  
> > "content": {  
> > "fragment\_size": 150,  
> > "number\_of\_fragments": 0,  
> > "no\_match\_size": 150  
> > }  
> > },  
> > "pre\_tags": [  
> > ""  
> > ],  
> > "post\_tags": [  
> > ""  
> > ]  
> > }  
> > }
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/5fffefc1-c2f3-4b2d-aa64-b804da6dc3ff%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5fffefc1-c2f3-4b2d-aa64-b804da6dc3ff%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/5fffefc1-c2f3-4b2d-aa64-b804da6dc3ff%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/5fffefc1-c2f3-4b2d-aa64-b804da6dc3ff%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/ae0cc53f-ab26-47d6-a4bb-4b2b3e59292d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ae0cc53f-ab26-47d6-a4bb-4b2b3e59292d%40googlegroups.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, 12:47am UTC](https://discuss.elastic.co/t/highlighting-is-not-working/20955/4 "2017-07-06T00:47:22Z")

</div>


