# Java client: unable to set highlighting encoder for a field

**URL:** https://discuss.elastic.co/t/java-client-unable-to-set-highlighting-encoder-for-a-field/142783
**Category:** Elasticsearch
**Created:** [August 2, 2018, 3:20pm UTC](https://discuss.elastic.co/t/java-client-unable-to-set-highlighting-encoder-for-a-field/142783 "2018-08-02T15:20:12Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Jean-Baptiste\_Nizet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jean-baptiste_nizet/32/34022_2.png) [@Jean-Baptiste\_Nizet](https://discuss.elastic.co/u/Jean-Baptiste_Nizet)
#### Post date: [August 2, 2018, 3:20pm UTC](https://discuss.elastic.co/t/java-client-unable-to-set-highlighting-encoder-for-a-field/142783/1 "2018-08-02T15:20:13Z")

</div>

Hello.

I'm trying to set the Highlighting `encoder` option to `"html"` instead of leaving the default for a specific field, and the Java API apparently has no way to do that (although the ElasticSearch reference documentation says we can override all highlighting settings for each field).

`HighlightBuilder` and `HighlightBuilder.Field` both extend `AbstractHighlighterBuilder`. HighlightBuilder has an `encoder(String)` method, but `HighlighBuilder.Field` doesn't.

This is not only annoying, but also a security issue since using the default strategy opens the door to HTML injection.

Also, BTW, the javadoc of `HighlightBuilder.encoder()` says that the two allowed values are "styled" and "default", but the reference documentation says the possible values are "html" and "default".

Is there something I'm missing, or is it indeed a missing method in the API?

---

<div class="post-metadata">

### Author: ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)
#### Post date: [August 10, 2018, 9:35am UTC](https://discuss.elastic.co/t/java-client-unable-to-set-highlighting-encoder-for-a-field/142783/2 "2018-08-10T09:35:08Z")

</div>

hi,  
as far as I can see the javadocs for `HighlightBuilder.encoder` are wrong. It is either `html` or `default`, I think you are right. Would you like to send a PR to correct that?

I believe this specific setting (encoder) cannot be overridden per field, I did not find a way to do that either, not only using the java API but also at REST sending a json request.

Cheers  
Luca

---

<div class="post-metadata">

### Author: ![Jean-Baptiste\_Nizet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jean-baptiste_nizet/32/34022_2.png) [@Jean-Baptiste\_Nizet](https://discuss.elastic.co/u/Jean-Baptiste_Nizet)
#### Post date: [August 10, 2018, 1:03pm UTC](https://discuss.elastic.co/t/java-client-unable-to-set-highlighting-encoder-for-a-field/142783/3 "2018-08-10T13:03:39Z")

</div>

I will try sending a PR. Thanks for your reply.

---

<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: [September 7, 2018, 1:03pm UTC](https://discuss.elastic.co/t/java-client-unable-to-set-highlighting-encoder-for-a-field/142783/4 "2018-09-07T13:03:40Z")

</div>

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