Highlight Field implementation in version 5.0


(Bluish Penguin) #1

Hi all,
I would like to upgrade code from version 2..4 to version 5.0.

response = client
          .prepareSearch(indexName)
          .setQuery(finalBuilder)
          .setScroll(new TimeValue(150000))
          .addHighlightedField("content").addHighlightedField("subject")
          .setHighlighterPreTags("<span class=\"H_HignLineText\">")
          .setHighlighterPostTags("</span>")
          .setSize(filter.getSize()).execute().actionGet();

But the methods "addHighlightedField", "setHighlighterPreTags" and "setHighlighterPostTags" are deprecated.
Anyone knows or any references on how to implement the highlighting in version 5?

Thank you.


(Christoph) #2

Hi,

all the highlighter related setters were moved to the HighlightBuilder. You can create a new HighlightBuilder, use on of the various field() methods on it and use preTags() or postTags() to change the tags. Then you add that highlighter to the SearchRequestBuilder using the highlighter(highlightBuilder) method.

So your example becomes something like:

HighlightBuilder hb = new HighlightBuilder();
hb.field("content").field("subject").preTags("...").postTags("...");


response = client
          .prepareSearch(indexName)
          .setQuery(finalBuilder)
          .setScroll(new TimeValue(150000))
          .highlightBuilder(hb)
          .setSize(filter.getSize()).execute().actionGet();

Hope this helps.


(Bluish Penguin) #3

It works. Thanks a lot.


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.