# Highlighting the wrong value

**URL:** <https://discuss.elastic.co/t/highlighting-the-wrong-value/8831>\
**Category:** Elasticsearch\
**Created:** [August 23, 2012, 3:02pm UTC](https://discuss.elastic.co/t/highlighting-the-wrong-value/8831 "2012-08-23T15:02:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oleg\_Ievtushok](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oleg_ievtushok/32/2745_2.png) [@Oleg\_Ievtushok](https://discuss.elastic.co/u/Oleg_Ievtushok)\
**Post date:** [August 23, 2012, 3:02pm UTC](https://discuss.elastic.co/t/highlighting-the-wrong-value/8831/1 "2012-08-23T15:02:10Z")

</div>

Hi everyone, I have the following scenario, where the wrong value is  
highlighted:

#!/bin/bash  
curl -XDELETE '[http://localhost:9200/highlight](http://localhost:9200/highlight)'  
curl -XPOST '[http://localhost:9200/highlight](http://localhost:9200/highlight)'  
curl -XPUT -d '{  
"doc" : {  
"\_source" : { "enabled" : false },  
"\_all" : { "enabled" : true },  
"\_timestamp" : { "enabled" : true, "store" : "yes" },  
"properties" : {  
"text1" : {  
"country" : "string",  
"store" : "yes"  
},  
"file" : {  
"type" : "string",  
"store" : "yes"  
}  
}  
}  
}' [http://localhost:9200/highlight/doc/\_mapping](http://localhost:9200/highlight/doc/_mapping)  
curl -XPOST -d '{ "country": "US and Canada", "file": "some keyword here  
and there" }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
curl -XPOST -d '{ "country": "US and Italy", "file": "you should not  
highlight Canada" }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
curl -XPOST -d '{ "country": "Brazil and France", "file": "whatever" }'  
[http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
curl -XPOST [http://localhost:9200/highlight/\_refresh](http://localhost:9200/highlight/_refresh)  
curl -XGET [http://localhost:9200/highlight/\_search?pretty=true](http://localhost:9200/highlight/_search?pretty=true) -d '{  
"query" : {  
"bool" : {  
"must" : [ {  
"field" : {  
"country" : "US Canada"  
}  
}, {  
"field" : {  
"file" : "keyword highlight"  
}  
} ]  
}  
},  
"highlight" : {  
"fields" : {  
"file" : {  
}  
}  
}  
}'

I was not expecting to get the "Canada" highlighted in the search result:  
"highlight" : {  
"file" : ["you should not _highlight_ _Canada_"]  
}

Is there any way to highlight only "highlight" word in this case?

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 23, 2012, 5:53pm UTC](https://discuss.elastic.co/t/highlighting-the-wrong-value/8831/2 "2012-08-23T17:53:23Z")

</div>

IMHO, highlighting process is applied at the end of the search process.  
That said, I suppose that highlight check for terms in file field. Terms is the full list of analyzed (or not) used in the query. (that's only a supposition as I did not look at the highlight code right now)

I'm curious of Elasticsearch gurus answers about this. Is it doable? Should Oleg open an issue for it?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 23 août 2012 à 17:02, Oleg Ievtushok [yevtushok@gmail.com](mailto:yevtushok@gmail.com) a écrit :

Hi everyone, I have the following scenario, where the wrong value is highlighted:

#!/bin/bash  
curl -XDELETE '[http://localhost:9200/highlight](http://localhost:9200/highlight)'  
curl -XPOST '[http://localhost:9200/highlight](http://localhost:9200/highlight)'  
curl -XPUT -d '{  
"doc" : {  
"\_source" : { "enabled" : false },  
"\_all" : { "enabled" : true },  
"\_timestamp" : { "enabled" : true, "store" : "yes" },  
"properties" : {  
"text1" : {  
"country" : "string",  
"store" : "yes"  
},  
"file" : {  
"type" : "string",  
"store" : "yes"  
}  
}  
}  
}' [http://localhost:9200/highlight/doc/\_mapping](http://localhost:9200/highlight/doc/_mapping)  
curl -XPOST -d '{ "country": "US and Canada", "file": "some keyword here and there" }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
curl -XPOST -d '{ "country": "US and Italy", "file": "you should not highlight Canada" }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
curl -XPOST -d '{ "country": "Brazil and France", "file": "whatever" }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
curl -XPOST [http://localhost:9200/highlight/\_refresh](http://localhost:9200/highlight/_refresh)  
curl -XGET [http://localhost:9200/highlight/\_search?pretty=true](http://localhost:9200/highlight/_search?pretty=true) -d '{  
"query" : {  
"bool" : {  
"must" : [ {  
"field" : {  
"country" : "US Canada"  
}  
}, {  
"field" : {  
"file" : "keyword highlight"  
}  
} ]  
}  
},  
"highlight" : {  
"fields" : {  
"file" : {  
}  
}  
}  
}'

I was not expecting to get the "Canada" highlighted in the search result:  
"highlight" : {  
"file" : ["you should not _highlight_ _Canada_"]  
}

## Is there any way to highlight only "highlight" word in this case?

--

---

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://discuss.elastic.co/u/phill)\
**Post date:** [August 29, 2012, 5:11pm UTC](https://discuss.elastic.co/t/highlighting-the-wrong-value/8831/3 "2012-08-29T17:11:23Z")

</div>

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

"|require\_field\_match| can be set to |true| which will cause a field to  
be highlighted _only if a query matched that field_. |false| means that  
terms are highlighted on all requested fields regardless if the query  
matches specifically on them."

On 8/23/2012 10:53 AM, David Pilato wrote:

> IMHO, highlighting process is applied at the end of the search process.  
> That said, I suppose that highlight check for terms in file field.  
> Terms is the full list of analyzed (or not) used in the query. (that's  
> only a supposition as I did not look at the highlight code right now)
> 
> I'm curious of Elasticsearch gurus answers about this. Is it doable?  
> Should Oleg open an issue for it?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 23 août 2012 à 17:02, Oleg Ievtushok \<[yevtushok@gmail.com](mailto:yevtushok@gmail.com)  
> [mailto:yevtushok@gmail.com](mailto:yevtushok@gmail.com)\> a écrit :
> 
> Hi everyone, I have the following scenario, where the wrong value is  
> highlighted:
> 
> #!/bin/bash  
> curl -XDELETE '[http://localhost:9200/highlight](http://localhost:9200/highlight)'  
> [http://localhost:9200/highlight'](http://localhost:9200/highlight%27)  
> curl -XPOST '[http://localhost:9200/highlight](http://localhost:9200/highlight)'  
> [http://localhost:9200/highlight'](http://localhost:9200/highlight%27)  
> curl -XPUT -d '{  
> "doc" : {  
> "\_source" : { "enabled" : false },  
> "\_all" : { "enabled" : true },  
> "\_timestamp" : { "enabled" : true, "store" : "yes" },  
> "properties" : {  
> "text1" : {  
> "country" : "string",  
> "store" : "yes"  
> },  
> "file" : {  
> "type" : "string",  
> "store" : "yes"  
> }  
> }  
> }  
> }' [http://localhost:9200/highlight/doc/\_mapping](http://localhost:9200/highlight/doc/_mapping)  
> curl -XPOST -d '{ "country": "US and Canada", "file": "some keyword  
> here and there" }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
> curl -XPOST -d '{ "country": "US and Italy", "file": "you should not  
> highlight Canada" }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
> curl -XPOST -d '{ "country": "Brazil and France", "file": "whatever"  
> }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
> curl -XPOST [http://localhost:9200/highlight/\_refresh](http://localhost:9200/highlight/_refresh)  
> curl -XGET [http://localhost:9200/highlight/\_search?pretty=true](http://localhost:9200/highlight/_search?pretty=true) -d '{  
> "query" : {  
> "bool" : {  
> "must" : [ {  
> "field" : {  
> "country" : "US Canada"  
> }  
> }, {  
> "field" : {  
> "file" : "keyword highlight"  
> }  
> } ]  
> }  
> },  
> "highlight" : {  
> "fields" : {  
> "file" : {  
> }  
> }  
> }  
> }'
> 
> I was not expecting to get the "Canada" highlighted in the search result:  
> "highlight" : {  
> "file" : ["you should not _highlight_ _Canada_"]  
> }
> 
> Is there any way to highlight only "highlight" word in this case?

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 29, 2012, 5:33pm UTC](https://discuss.elastic.co/t/highlighting-the-wrong-value/8831/4 "2012-08-29T17:33:20Z")

</div>

Thanks! Good to know!

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 29 août 2012 à 19:12, "P. Hill" [parehill1@gmail.com](mailto:parehill1@gmail.com) a écrit :

> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/highlighting.html)
> 
> "|require\_field\_match| can be set to |true| which will cause a field to be highlighted _only if a query matched that field_. |false| means that terms are highlighted on all requested fields regardless if the query matches specifically on them."
> 
> On 8/23/2012 10:53 AM, David Pilato wrote:
> 
> > IMHO, highlighting process is applied at the end of the search process.  
> > That said, I suppose that highlight check for terms in file field. Terms is the full list of analyzed (or not) used in the query. (that's only a supposition as I did not look at the highlight code right now)
> > 
> > I'm curious of Elasticsearch gurus answers about this. Is it doable? Should Oleg open an issue for it?
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 23 août 2012 à 17:02, Oleg Ievtushok \<[yevtushok@gmail.com](mailto:yevtushok@gmail.com) [mailto:yevtushok@gmail.com](mailto:yevtushok@gmail.com)\> a écrit :
> > 
> > Hi everyone, I have the following scenario, where the wrong value is highlighted:
> > 
> > #!/bin/bash  
> > curl -XDELETE '[http://localhost:9200/highlight](http://localhost:9200/highlight)' [http://localhost:9200/highlight'](http://localhost:9200/highlight%27)  
> > curl -XPOST '[http://localhost:9200/highlight](http://localhost:9200/highlight)' [http://localhost:9200/highlight'](http://localhost:9200/highlight%27)  
> > curl -XPUT -d '{  
> > "doc" : {  
> > "\_source" : { "enabled" : false },  
> > "\_all" : { "enabled" : true },  
> > "\_timestamp" : { "enabled" : true, "store" : "yes" },  
> > "properties" : {  
> > "text1" : {  
> > "country" : "string",  
> > "store" : "yes"  
> > },  
> > "file" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > }  
> > }  
> > }  
> > }' [http://localhost:9200/highlight/doc/\_mapping](http://localhost:9200/highlight/doc/_mapping)  
> > curl -XPOST -d '{ "country": "US and Canada", "file": "some keyword here and there" }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
> > curl -XPOST -d '{ "country": "US and Italy", "file": "you should not highlight Canada" }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
> > curl -XPOST -d '{ "country": "Brazil and France", "file": "whatever" }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
> > curl -XPOST [http://localhost:9200/highlight/\_refresh](http://localhost:9200/highlight/_refresh)  
> > curl -XGET [http://localhost:9200/highlight/\_search?pretty=true](http://localhost:9200/highlight/_search?pretty=true) -d '{  
> > "query" : {  
> > "bool" : {  
> > "must" : [ {  
> > "field" : {  
> > "country" : "US Canada"  
> > }  
> > }, {  
> > "field" : {  
> > "file" : "keyword highlight"  
> > }  
> > } ]  
> > }  
> > },  
> > "highlight" : {  
> > "fields" : {  
> > "file" : {  
> > }  
> > }  
> > }  
> > }'
> > 
> > I was not expecting to get the "Canada" highlighted in the search result:  
> > "highlight" : {  
> > "file" : ["you should not _highlight_ _Canada_"]  
> > }
> > 
> > Is there any way to highlight only "highlight" word in this case?
> 
> --

--

---

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://discuss.elastic.co/u/phill)\
**Post date:** [August 30, 2012, 12:11am UTC](https://discuss.elastic.co/t/highlighting-the-wrong-value/8831/5 "2012-08-30T00:11:46Z")

</div>

But don't put me in the league of ES gurus, please. I recalled seeing  
that info when I was reading about ES and recognized that as something  
that triggers the behavior down in the Lucene HitHighlighter(s) which I  
have had a love/hate relationship with over the last year when working  
directly with Lucene.

-Paul

On 8/29/2012 10:33 AM, David Pilato wrote:

> Thanks! Good to know!

--

---

<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, 3:14am UTC](https://discuss.elastic.co/t/highlighting-the-wrong-value/8831/6 "2017-07-06T03:14:41Z")

</div>


