# Highlighting not appearing sometimes

**URL:** <https://discuss.elastic.co/t/highlighting-not-appearing-sometimes/4618>\
**Category:** Elasticsearch\
**Created:** [June 14, 2011, 6:10pm UTC](https://discuss.elastic.co/t/highlighting-not-appearing-sometimes/4618 "2011-06-14T18:10:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Mill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_mill/32/3124_2.png) [@Eric\_Mill](https://discuss.elastic.co/u/Eric_Mill)\
**Post date:** [June 14, 2011, 6:10pm UTC](https://discuss.elastic.co/t/highlighting-not-appearing-sometimes/4618/1 "2011-06-14T18:10:36Z")

</div>

Is there any reason why a search result might not include highlighting for a  
given query, when highlighting is requested, and there's a match?

I'm doing a "text" query of type "phrase", and for 4 out of the 5 hits in  
the response, there's a highlight section returned, with proper  
highlighting. On one of them, there's no highlighting at all, but when I  
look at the field on the source document, I can see at least three instances  
of the query (a single word) in the field.

-- Eric

---

<div class="post-metadata">

**Author:** ![ofavre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ofavre/32/116819_2.png) [@ofavre](https://discuss.elastic.co/u/ofavre)\
**Post date:** [July 13, 2011, 3:57pm UTC](https://discuss.elastic.co/t/highlighting-not-appearing-sometimes/4618/2 "2011-07-13T15:57:43Z")

</div>

Make sure you have term\_vector=with\_positions\_offsets in your mapping for  
the relevant fields.  
Otherwise, ES will reanalyze the field and try to match the term searched.  
It can miss many occurrences if some stemming is performed.

--  
Olivier Favre

[www.yakaz.com](http://www.yakaz.com)

2011/6/14 Eric Mill [kprojection@gmail.com](mailto:kprojection@gmail.com)

> Is there any reason why a search result might not include highlighting for  
> a given query, when highlighting is requested, and there's a match?
> 
> I'm doing a "text" query of type "phrase", and for 4 out of the 5 hits in  
> the response, there's a highlight section returned, with proper  
> highlighting. On one of them, there's no highlighting at all, but when I  
> look at the field on the source document, I can see at least three instances  
> of the query (a single word) in the field.
> 
> -- Eric

---

<div class="post-metadata">

**Author:** ![ofavre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ofavre/32/116819_2.png) [@ofavre](https://discuss.elastic.co/u/ofavre)\
**Post date:** [July 21, 2011, 4:58pm UTC](https://discuss.elastic.co/t/highlighting-not-appearing-sometimes/4618/3 "2011-07-21T16:58:52Z")

</div>

Hey, I'm hitting the same bug. I thought it was fixed by what I suggested in  
my previous mail, but I got wrong somehow...

I propose the following patch for it. See attached file.  
If it seems acceptable, I'll be glad to do a pull-request for:  
[https://github.com/ofavre/elasticsearch/commit/70509e431d03784b8d1957151630b0a784e021f5](https://github.com/ofavre/elasticsearch/commit/70509e431d03784b8d1957151630b0a784e021f5)  
(master)

> <https://github.com/ofavre/elasticsearch/commit/3ba37163d42a53f30b6a602ca4a228d86a93e3ab>

(0.17)

By the way, I have a question for the Lucene community. (In absence of  
answer from kimchy, I'll post to Lucene's dev mailing-list).  
Why does FieldQuery rewrites queries extensively? (With potential recursion  
problems)  
Why doesn't they use extractTerms() after one rewrite (which can eliminate  
terms from "must\_not" clauses from BooleanQuerys etc.)?  
Afterall, (in the fast highlighter), it's the matched terms that we are  
highlighting...

## Best regards,

Olivier Favre

[www.yakaz.com](http://www.yakaz.com)

2011/7/13 Olivier Favre [olivier@yakaz.com](mailto:olivier@yakaz.com)

> Make sure you have term\_vector=with\_positions\_offsets in your mapping for  
> the relevant fields.  
> Otherwise, ES will reanalyze the field and try to match the term searched.  
> It can miss many occurrences if some stemming is performed.
> 
> --  
> Olivier Favre
> 
> [www.yakaz.com](http://www.yakaz.com)
> 
> 2011/6/14 Eric Mill [kprojection@gmail.com](mailto:kprojection@gmail.com)
> 
> > Is there any reason why a search result might not include highlighting for  
> > a given query, when highlighting is requested, and there's a match?
> > 
> > I'm doing a "text" query of type "phrase", and for 4 out of the 5 hits in  
> > the response, there's a highlight section returned, with proper  
> > highlighting. On one of them, there's no highlighting at all, but when I  
> > look at the field on the source document, I can see at least three instances  
> > of the query (a single word) in the field.
> > 
> > -- Eric

---

<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 22, 2011, 12:52am UTC](https://discuss.elastic.co/t/highlighting-not-appearing-sometimes/4618/4 "2011-07-22T00:52:01Z")

</div>

I need to dive again into the highlighter impl to check, maybe you can ask  
on the lucene mailing list as well...

On Thu, Jul 21, 2011 at 7:58 PM, Olivier Favre [olivier@yakaz.com](mailto:olivier@yakaz.com) wrote:

> Hey, I'm hitting the same bug. I thought it was fixed by what I suggested  
> in my previous mail, but I got wrong somehow...
> 
> I propose the following patch for it. See attached file.  
> If it seems acceptable, I'll be glad to do a pull-request for:
> 
> [https://github.com/ofavre/elasticsearch/commit/70509e431d03784b8d1957151630b0a784e021f5](https://github.com/ofavre/elasticsearch/commit/70509e431d03784b8d1957151630b0a784e021f5)  
> (master)
> 
> [Fix for highlighting any query, using extactedTerms() instead of rewr… · ofavre/elasticsearch@3ba3716 · GitHub](https://github.com/ofavre/elasticsearch/commit/3ba37163d42a53f30b6a602ca4a228d86a93e3ab)  
> (0.17)
> 
> By the way, I have a question for the Lucene community. (In absence of  
> answer from kimchy, I'll post to Lucene's dev mailing-list).  
> Why does FieldQuery rewrites queries extensively? (With potential recursion  
> problems)  
> Why doesn't they use extractTerms() after one rewrite (which can eliminate  
> terms from "must\_not" clauses from BooleanQuerys etc.)?  
> Afterall, (in the fast highlighter), it's the matched terms that we are  
> highlighting...
> 
> ## Best regards,
> 
> Olivier Favre
> 
> [www.yakaz.com](http://www.yakaz.com)
> 
> 2011/7/13 Olivier Favre [olivier@yakaz.com](mailto:olivier@yakaz.com)
> 
> > Make sure you have term\_vector=with\_positions\_offsets in your mapping for  
> > the relevant fields.  
> > Otherwise, ES will reanalyze the field and try to match the term searched.  
> > It can miss many occurrences if some stemming is performed.
> > 
> > --  
> > Olivier Favre
> > 
> > [www.yakaz.com](http://www.yakaz.com)
> > 
> > 2011/6/14 Eric Mill [kprojection@gmail.com](mailto:kprojection@gmail.com)
> > 
> > > Is there any reason why a search result might not include highlighting  
> > > for a given query, when highlighting is requested, and there's a match?
> > > 
> > > I'm doing a "text" query of type "phrase", and for 4 out of the 5 hits in  
> > > the response, there's a highlight section returned, with proper  
> > > highlighting. On one of them, there's no highlighting at all, but when I  
> > > look at the field on the source document, I can see at least three instances  
> > > of the query (a single word) in the field.
> > > 
> > > -- Eric

---

<div class="post-metadata">

**Author:** ![ofavre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ofavre/32/116819_2.png) [@ofavre](https://discuss.elastic.co/u/ofavre)\
**Post date:** [July 22, 2011, 2:47pm UTC](https://discuss.elastic.co/t/highlighting-not-appearing-sometimes/4618/5 "2011-07-22T14:47:16Z")

</div>

Here is the JIRA issue I've initiated:  
[https://issues.apache.org/jira/browse/LUCENE-3332?focusedCommentId=13069565](https://issues.apache.org/jira/browse/LUCENE-3332?focusedCommentId=13069565)

--  
Olivier Favre

[www.yakaz.com](http://www.yakaz.com)

2011/7/22 Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)

> I need to dive again into the highlighter impl to check, maybe you can ask  
> on the lucene mailing list as well...
> 
> On Thu, Jul 21, 2011 at 7:58 PM, Olivier Favre [olivier@yakaz.com](mailto:olivier@yakaz.com) wrote:
> 
> > Hey, I'm hitting the same bug. I thought it was fixed by what I suggested  
> > in my previous mail, but I got wrong somehow...
> > 
> > I propose the following patch for it. See attached file.  
> > If it seems acceptable, I'll be glad to do a pull-request for:
> > 
> > [https://github.com/ofavre/elasticsearch/commit/70509e431d03784b8d1957151630b0a784e021f5](https://github.com/ofavre/elasticsearch/commit/70509e431d03784b8d1957151630b0a784e021f5)  
> > (master)
> > 
> > [Fix for highlighting any query, using extactedTerms() instead of rewr… · ofavre/elasticsearch@3ba3716 · GitHub](https://github.com/ofavre/elasticsearch/commit/3ba37163d42a53f30b6a602ca4a228d86a93e3ab)  
> > (0.17)
> > 
> > By the way, I have a question for the Lucene community. (In absence of  
> > answer from kimchy, I'll post to Lucene's dev mailing-list).  
> > Why does FieldQuery rewrites queries extensively? (With potential  
> > recursion problems)  
> > Why doesn't they use extractTerms() after one rewrite (which can eliminate  
> > terms from "must\_not" clauses from BooleanQuerys etc.)?  
> > Afterall, (in the fast highlighter), it's the matched terms that we are  
> > highlighting...
> > 
> > ## Best regards,
> > 
> > Olivier Favre
> > 
> > [www.yakaz.com](http://www.yakaz.com)
> > 
> > 2011/7/13 Olivier Favre [olivier@yakaz.com](mailto:olivier@yakaz.com)
> > 
> > > Make sure you have term\_vector=with\_positions\_offsets in your mapping  
> > > for the relevant fields.  
> > > Otherwise, ES will reanalyze the field and try to match the term  
> > > searched.  
> > > It can miss many occurrences if some stemming is performed.
> > > 
> > > --  
> > > Olivier Favre
> > > 
> > > [www.yakaz.com](http://www.yakaz.com)
> > > 
> > > 2011/6/14 Eric Mill [kprojection@gmail.com](mailto:kprojection@gmail.com)
> > > 
> > > > Is there any reason why a search result might not include highlighting  
> > > > for a given query, when highlighting is requested, and there's a match?
> > > > 
> > > > I'm doing a "text" query of type "phrase", and for 4 out of the 5 hits  
> > > > in the response, there's a highlight section returned, with proper  
> > > > highlighting. On one of them, there's no highlighting at all, but when I  
> > > > look at the field on the source document, I can see at least three instances  
> > > > of the query (a single word) in the field.
> > > > 
> > > > -- Eric

---

<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:59am UTC](https://discuss.elastic.co/t/highlighting-not-appearing-sometimes/4618/6 "2017-07-06T03:59:49Z")

</div>


