Possible bug with highlighted terms when setting type in search

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.

I believe I fixed this with 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.

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.