# Possible bug with highlighted terms when setting type in search

**URL:** <https://discuss.elastic.co/t/possible-bug-with-highlighted-terms-when-setting-type-in-search/42903>\
**Category:** Elasticsearch\
**Created:** [February 26, 2016, 11:45pm UTC](https://discuss.elastic.co/t/possible-bug-with-highlighted-terms-when-setting-type-in-search/42903 "2016-02-26T23:45:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cocote](https://avatars.discourse-cdn.com/v4/letter/c/eb9ed0/32.png) [@cocote](https://discuss.elastic.co/u/cocote)\
**Post date:** [February 26, 2016, 11:45pm UTC](https://discuss.elastic.co/t/possible-bug-with-highlighted-terms-when-setting-type-in-search/42903/1 "2016-02-26T23:45:18Z")

</div>

Hello,

I think I came across a small bug with the highlighting in the Java API in ElasticSearch 2.1.1.

Sometimes the highlighted terms appear to be the ones queried but also the types set in the search.

```
//create a JSONObject of type "contact" 
//that contains the string "contact" in a field
JSONObject j = new JSONObject();
j.put("content", "foo contact");

//index the object
client.prepareIndex().setIndex(index).setType("contact")
        .setSource(j.toString()).execute().actionGet();

//query for a string in _all fields
QueryBuilder query = QueryBuilders.commonTermsQuery("_all", "foo");
        
//run a search for the "contact" type
SearchRequestBuilder builder = client.prepareSearch(index)
        .setQuery(query)
        .setTypes(new String[] {"contact"})
        .addHighlightedField("content")
        .setHighlighterRequireFieldMatch(false);

```

Expected result of the highlighted fragment: `<em>foo</em> contact`  
Actual result: `<em>foo</em> <em>contact</em>`

If I just remove the `.setTypes(new String[] {"contact"})` line, then I get the expected result.

I don't know if this has been reported before or if I'm wrong about the expected result but it seems odd.

Best regards.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [February 27, 2016, 3:05am UTC](https://discuss.elastic.co/t/possible-bug-with-highlighted-terms-when-setting-type-in-search/42903/2 "2016-02-27T03:05:18Z")

</div>

I believe I fixed this with [https://github.com/elastic/elasticsearch/pull/15793](https://github.com/elastic/elasticsearch/pull/15793) . According to the tags it should be fixed in 2.3 For now I think you can work around it with highlight\_query.

---

<div class="post-metadata">

**Author:** ![cocote](https://avatars.discourse-cdn.com/v4/letter/c/eb9ed0/32.png) [@cocote](https://discuss.elastic.co/u/cocote)\
**Post date:** [February 29, 2016, 8:39am UTC](https://discuss.elastic.co/t/possible-bug-with-highlighted-terms-when-setting-type-in-search/42903/3 "2016-02-29T08:39:12Z")

</div>

Thanks.

It wasn't a real issue for me since I changed the name of the types I was using. I wanted to report it and I'm glad it will be fixed in the next version.

---

<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 5, 2017, 11:12pm UTC](https://discuss.elastic.co/t/possible-bug-with-highlighted-terms-when-setting-type-in-search/42903/4 "2017-07-05T23:12:55Z")

</div>


