# Highlight Field implementation in version 5.0

**URL:** <https://discuss.elastic.co/t/highlight-field-implementation-in-version-5-0/66697>\
**Category:** Elasticsearch\
**Created:** [November 21, 2016, 10:34am UTC](https://discuss.elastic.co/t/highlight-field-implementation-in-version-5-0/66697 "2016-11-21T10:34:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluish\_penguin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bluish_penguin/32/13769_2.png) [@bluish\_penguin](https://discuss.elastic.co/u/bluish_penguin)\
**Post date:** [November 21, 2016, 10:34am UTC](https://discuss.elastic.co/t/highlight-field-implementation-in-version-5-0/66697/1 "2016-11-21T10:34:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [November 21, 2016, 11:07am UTC](https://discuss.elastic.co/t/highlight-field-implementation-in-version-5-0/66697/2 "2016-11-21T11:07:39Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![bluish\_penguin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bluish_penguin/32/13769_2.png) [@bluish\_penguin](https://discuss.elastic.co/u/bluish_penguin)\
**Post date:** [November 23, 2016, 3:00am UTC](https://discuss.elastic.co/t/highlight-field-implementation-in-version-5-0/66697/3 "2016-11-23T03:00:02Z")

</div>

It works. Thanks a lot.

---

<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:** [December 21, 2016, 3:00am UTC](https://discuss.elastic.co/t/highlight-field-implementation-in-version-5-0/66697/4 "2016-12-21T03:00:10Z")

</div>

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