# Highlighting API

**URL:** <https://discuss.elastic.co/t/highlighting-api/3134>\
**Category:** Elasticsearch\
**Created:** [July 21, 2010, 2:37pm UTC](https://discuss.elastic.co/t/highlighting-api/3134 "2010-07-21T14:37:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [July 21, 2010, 2:37pm UTC](https://discuss.elastic.co/t/highlighting-api/3134/1 "2010-07-21T14:37:13Z")

</div>

Hi,

how are PRE and POST tags supposed to work in highlighting?

Assume I use:  
pre\_Tags : ["tag1", "tag2"],  
post\_tags : ["tag1", "tag2"],

The documentation[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/#Highlighting](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/#Highlighting)says:  
There can be a single tag or more, and the “importance” is ordered.

What does it mean?

I did not find any unit test for that in ES code.  
Also I think there might be an issue in the code because if I use "styled"  
schema then all of my highlighted fragments used only the first tag from the  
internal array: i.e.   
_So the question is when can I expect the other tags being used? (hlt2, hlt3,  
...)_

Two issues to be fixed:

1. the internal STYLED\_PRE\_TAG array contains two entries for hlt2  
(copy&paste?). See  
[http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L53](http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L53)  
and this issue propagated into doc as well:  
[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/#Highlighting](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/#Highlighting)

2. the doc  
[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/#Highlighting](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/#Highlighting)  
uses  
"tag\_schema"  
but the code  
[http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L90](http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L90)  
uses  
"tags\_schema"

Which one is correct? (I assume the code is right, thus "tags\_schema")

Regards,  
Lukas

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 21, 2010, 5:40pm UTC](https://discuss.elastic.co/t/highlighting-api/3134/2 "2010-07-21T17:40:46Z")

</div>

On Wed, Jul 21, 2010 at 5:37 PM, Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com) wrote:

> Hi,
> 
> how are PRE and POST tags supposed to work in highlighting?
> 
> Assume I use:  
> pre\_Tags : ["tag1", "tag2"],  
> post\_tags : ["tag1", "tag2"],
> 
> The documentation[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/#Highlighting](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/#Highlighting)says:  
> There can be a single tag or more, and the “importance” is ordered.
> 
> What does it mean?

The Lucene vector highlighter tries to "score" a highlighted hit and that  
score is how important it is.

> I did not find any unit test for that in ES code.  
> Also I think there might be an issue in the code because if I use "styled"  
> schema then all of my highlighted fragments used only the first tag from the  
> internal array: i.e.   
> _So the question is when can I expect the other tags being used?  
> (hlt2, hlt3, ...)_

 

_Depends on your text and your search query._

 

_> Two issues to be fixed:
> 
> 1. the internal STYLED\_PRE\_TAG array contains two entries for hlt2  
> (copy&paste?). See  
> [http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L53](http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L53)  
> and this issue propagated into doc as well:  
> [http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/#Highlighting](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/#Highlighting)_

 

_Yea, i fixed it in the code, can you fix the docs?_

 

_> 1. the doc  
> [http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/#Highlighting](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/#Highlighting)  
> uses  
> "tag\_schema"  
> but the code  
> [http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L90](http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L90)  
> uses  
> "tags\_schema"
> 
> Which one is correct? (I assume the code is right, thus "tags\_schema")_

 

_The code is always right ;), its tags\_schema, can you fix that in the docs  
as well?_

 

_> Regards,  
> Lukas_

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [July 21, 2010, 5:55pm UTC](https://discuss.elastic.co/t/highlighting-api/3134/3 "2010-07-21T17:55:33Z")

</div>

Fixed the docs.

On Wed, Jul 21, 2010 at 7:40 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> On Wed, Jul 21, 2010 at 5:37 PM, Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com)wrote:
> 
> > Hi,
> > 
> > how are PRE and POST tags supposed to work in highlighting?
> > 
> > Assume I use:  
> > pre\_Tags : ["tag1", "tag2"],  
> > post\_tags : ["tag1", "tag2"],
> > 
> > The documentation[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/#Highlighting](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/#Highlighting)says:  
> > There can be a single tag or more, and the “importance” is ordered.
> > 
> > What does it mean?
> 
> The Lucene vector highlighter tries to "score" a highlighted hit and that  
> score is how important it is.

Let's say I have two pre\_tags, then the first one is used if the score is \>  
0.5 and the second tag is used if score \< 0.5 ?  
Something like that?

> > I did not find any unit test for that in ES code.  
> > Also I think there might be an issue in the code because if I use "styled"  
> > schema then all of my highlighted fragments used only the first tag from the  
> > internal array: i.e.   
> > _So the question is when can I expect the other tags being used?  
> > (hlt2, hlt3, ...)_
> 
>  
> 
> _Depends on your text and your search query._
> 
>  
> 
> _> Two issues to be fixed:
> > 
> > 1. the internal STYLED\_PRE\_TAG array contains two entries for hlt2  
> > (copy&paste?). See  
> > [http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L53](http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L53)  
> > and this issue propagated into doc as well:  
> > [http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/#Highlighting](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/#Highlighting)_
> 
>  
> 
> _Yea, i fixed it in the code, can you fix the docs?_
> 
>  
> 
> _> 1. the doc  
> > [http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/#Highlighting](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/#Highlighting)  
> > uses  
> > "tag\_schema"  
> > but the code  
> > [http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L90](http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L90)  
> > uses  
> > "tags\_schema"
> > 
> > Which one is correct? (I assume the code is right, thus "tags\_schema")_
> 
>  
> 
> _The code is always right ;), its tags\_schema, can you fix that in the docs  
> as well?_
> 
>  
> 
> _> Regards,  
> > Lukas_

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 21, 2010, 6:18pm UTC](https://discuss.elastic.co/t/highlighting-api/3134/4 "2010-07-21T18:18:46Z")

</div>

On Wed, Jul 21, 2010 at 8:55 PM, Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com) wrote:

> Fixed the docs.

thanks!

> On Wed, Jul 21, 2010 at 7:40 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> > On Wed, Jul 21, 2010 at 5:37 PM, Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com)wrote:
> > 
> > > Hi,
> > > 
> > > how are PRE and POST tags supposed to work in highlighting?
> > > 
> > > Assume I use:  
> > > pre\_Tags : ["tag1", "tag2"],  
> > > post\_tags : ["tag1", "tag2"],
> > > 
> > > The documentation[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/#Highlighting](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/#Highlighting)says:  
> > > There can be a single tag or more, and the “importance” is ordered.
> > > 
> > > What does it mean?
> > 
> > The Lucene vector highlighter tries to "score" a highlighted hit and that  
> > score is how important it is.
> 
> Let's say I have two pre\_tags, then the first one is used if the score is \>  
> 0.5 and the second tag is used if score \< 0.5 ?  
> Something like that?

yes, though don't confuse it with search hits scoring.

> > > I did not find any unit test for that in ES code.  
> > > Also I think there might be an issue in the code because if I use  
> > > "styled" schema then all of my highlighted fragments used only the first tag  
> > > from the internal array: i.e.   
> > > _So the question is when can I expect the other tags being used?  
> > > (hlt2, hlt3, ...)_
> > 
> >  
> > 
> > _Depends on your text and your search query._
> > 
> >  
> > 
> > _> Two issues to be fixed:
> > > 
> > > 1. the internal STYLED\_PRE\_TAG array contains two entries for hlt2  
> > > (copy&paste?). See  
> > > [http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L53](http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L53)  
> > > and this issue propagated into doc as well:  
> > > [http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/#Highlighting](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/#Highlighting)_
> > 
> >  
> > 
> > _Yea, i fixed it in the code, can you fix the docs?_
> > 
> >  
> > 
> > _> 1. the doc  
> > > [http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/#Highlighting](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/#Highlighting)  
> > > uses  
> > > "tag\_schema"  
> > > but the code  
> > > [http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L90](http://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java#L90)  
> > > uses  
> > > "tags\_schema"
> > > 
> > > Which one is correct? (I assume the code is right, thus "tags\_schema")_
> > 
> >  
> > 
> > _The code is always right ;), its tags\_schema, can you fix that in the docs  
> > as well?_
> > 
> >  
> > 
> > _> Regards,  
> > > Lukas_

---

<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, 4:21am UTC](https://discuss.elastic.co/t/highlighting-api/3134/5 "2017-07-06T04:21:51Z")

</div>


