Q: addHighlightedField() method does not work for termsQuery in Elasticsearch I have a index named blog  in ES server.Its type is article.Every document belongs to blog/article has three field:title、abstractandcontent.For example:
{
  "_index": "blog",
  "_type": "article",
  "_id": "2",
  "_score": 1,
  "_source": {
     "id": 2,
     "title": "Install Git on Windows",
     "abstract": " Git Installation guide",
     "content": "Git is easy to learn and has a tiny ... "
  }
}

I build a termsQuery to search documets including git:
QueryBuilder termquery1 = QueryBuilders.termsQuery("_all", "git");
SearchResponse response1 =client.prepareSearch().setQuery(termquery1)
                          .addHighlightedField("title")
                          .execute().actionGet();
SearchHits hits = response1.getHits();
for (SearchHit hit : hits) {
        HighlightField hField=hit.getHighlightFields().get("title");
        System.out.println(hit.getSource() + "\t" + hit.getHighlightFields());
       System.out.println(hField);
}

System.out.println(hField) print null, My goal is to make key word git highlight in all the fields.how to achieve that?

A: I read elasticsearch reference Elasticsearch Reference [2.3] » Mapping » Meta-Fields » _all field#highlighting-all-field and found the reason.

Highlighting and the _all field
A field can only be used for highlighting if the original string value
is available, either from the _source field or as a stored field.
The _all field is not present in the _source field and it is not
stored by default, and so cannot be highlighted. There are two
options. Either store the _all field or highlight the original fields.
Store the _all fieldedit
If store is set to true, then the original
field value is retrievable and can be highlighted.

I change my mapping to set _all be stored.
{
 "blog": {
     "mappings": {
         "article": {
             "_all": {
                 "store": true,
                "analyzer": "ik_max_word"
             }
         }
     }
 }
}

Then I change termsQuery to queryStringQuery:
QueryBuilder strQuery = QueryBuilders.queryStringQuery("git");

then change search method:
SearchResponse response1 = client.prepareSearch()
                                 .addHighlightedField("_all")
                                 .setHighlighterPreTags("<span color=\"red\">")
                                 .setHighlighterPostTags("</span>")
                                 .setQuery(strQuery).execute().actionGet();

for (SearchHit hit : hits) {
                    HighlightField hField=hit.getHighlightFields().get("_all");
                    System.out.println("score:"+hit.getScore()+"id:"+hit.getId()
                                       +"\n"+hit.getSourceAsString());
                    System.out.println(hField);
                }
        

