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.