# Highlighting several fields under separate indexes for a query string in elastic search

**URL:** <https://discuss.elastic.co/t/highlighting-several-fields-under-separate-indexes-for-a-query-string-in-elastic-search/40729>\
**Category:** Elasticsearch\
**Created:** [February 2, 2016, 1:23pm UTC](https://discuss.elastic.co/t/highlighting-several-fields-under-separate-indexes-for-a-query-string-in-elastic-search/40729 "2016-02-02T13:23:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shivang\_Sarawagi](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@Shivang\_Sarawagi](https://discuss.elastic.co/u/Shivang_Sarawagi)\
**Post date:** [February 2, 2016, 1:23pm UTC](https://discuss.elastic.co/t/highlighting-several-fields-under-separate-indexes-for-a-query-string-in-elastic-search/40729/1 "2016-02-02T13:23:24Z")

</div>

I went through a [StackOverflow](http://stackoverflow.com/questions/25105147/elasticsearch-highlight-how-to-get-entire-text-of-the-field-in-java-client) question to know how to highlight a response field with elastic search java api but in the code there is only one index "book" being passed in the prepareSearch(index) method

```
client.prepareSearch("book")
 .setTypes("history")
 .addHighlightedField("title")
 .setQuery(query)
 .setHighlighterFragmentSize(2000)
 .setHighlighterNumOfFragments(1);

```

the response returns the highlighted field. The problem with my code is I have several indexes, actually an index array being passed to the prepareSearch method with three different indexes. Each index has several fields, I need to highlight all the fields for a particular query string.

```
    SearchRequestBuilder srb =client.prepareSearch(indexArray);
    srb.addHighlightedField("name");
    srb.addHighlightedField("title"); //field of second index
    srb.addHighlightedField("description"); //field of second index

```

in the response the highlighted field is only of the first index in the array. The other fields of other indexes are not highlighted.

Can anyone tell me how do I achieve that?

For three index I get three response objects Response for the first index

```
hits" : [ {
      "_index" : "abcde2016-0125-1607", // 1st Index
      "_type" : "product",
      "_id" : "2542",
      "_score" : 2.6031399,
      "fields" : {
        "name" : ["Google Cluster F100"],
        "level" : [56]
      },
      "highlight" : {
        "name" : ["<em>Google</em> Cluster F100"]
      }
    }, 

```

For other response objects of second & third index I do not receive the highlight tag

---

<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:19pm UTC](https://discuss.elastic.co/t/highlighting-several-fields-under-separate-indexes-for-a-query-string-in-elastic-search/40729/2 "2017-07-05T23:19:41Z")

</div>


