# Is there any approach in java using which we can find out the list of indexes contributed in creating response against the query fired

**URL:** https://discuss.elastic.co/t/is-there-any-approach-in-java-using-which-we-can-find-out-the-list-of-indexes-contributed-in-creating-response-against-the-query-fired/167085
**Category:** Elasticsearch
**Created:** [February 5, 2019, 9:04am UTC](https://discuss.elastic.co/t/is-there-any-approach-in-java-using-which-we-can-find-out-the-list-of-indexes-contributed-in-creating-response-against-the-query-fired/167085 "2019-02-05T09:04:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![BleedCode](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@BleedCode](https://discuss.elastic.co/u/BleedCode)
#### Post date: [February 5, 2019, 9:04am UTC](https://discuss.elastic.co/t/is-there-any-approach-in-java-using-which-we-can-find-out-the-list-of-indexes-contributed-in-creating-response-against-the-query-fired/167085/1 "2019-02-05T09:04:45Z")

</div>

Is there any approach in java using which we can find out the list of indexes contributed in creating response against the query fired.

Example: A query is executed against 5 indices in one request and only 2 contributed in generating the response, so i am looking for a way by which i should get the names of indexes which contributed in response and ignore the remaining 3.

**[http://localhost:9200/index1](http://localhost:9200/index1), index2, index3, index4, index5/\_search**

In all these 5 index, inde1 and index 2 is contributing in producing response.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [February 5, 2019, 9:19am UTC](https://discuss.elastic.co/t/is-there-any-approach-in-java-using-which-we-can-find-out-the-list-of-indexes-contributed-in-creating-response-against-the-query-fired/167085/2 "2019-02-05T09:19:29Z")

</div>

The `SearchHit` exposes the `getIndex()` method:

> <https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/search/SearchHit.java#L325-L327>

Or may be you would like to run a Terms agg on `_index` field?

---

<div class="post-metadata">

### Author: ![BleedCode](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@BleedCode](https://discuss.elastic.co/u/BleedCode)
#### Post date: [February 7, 2019, 4:59am UTC](https://discuss.elastic.co/t/is-there-any-approach-in-java-using-which-we-can-find-out-the-list-of-indexes-contributed-in-creating-response-against-the-query-fired/167085/3 "2019-02-07T04:59:37Z")

</div>

Thanks @dadoonet it worked 👍

---

<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: [March 7, 2019, 4:59am UTC](https://discuss.elastic.co/t/is-there-any-approach-in-java-using-which-we-can-find-out-the-list-of-indexes-contributed-in-creating-response-against-the-query-fired/167085/4 "2019-03-07T04:59:43Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
