# In JAVA how to pass list of indexes as paramater to search api

**URL:** <https://discuss.elastic.co/t/in-java-how-to-pass-list-of-indexes-as-paramater-to-search-api/145542>\
**Category:** Elasticsearch\
**Created:** [August 22, 2018, 11:20am UTC](https://discuss.elastic.co/t/in-java-how-to-pass-list-of-indexes-as-paramater-to-search-api/145542 "2018-08-22T11:20:19Z")\
**Posts on this page:** 2\
**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:** [August 22, 2018, 11:20am UTC](https://discuss.elastic.co/t/in-java-how-to-pass-list-of-indexes-as-paramater-to-search-api/145542/1 "2018-08-22T11:20:19Z")

</div>

I am trying to use multi-index search api of ES in java. The list of indexes over which i will be performing search operation will be known at run-time only. Using below snippet of code i am able to perform search when the indexes are known.

> Search search = new Search.Builder(query).addIndex("index1")  
> .addIndex("index2").addType("type").build();

How can i make it work for a dynamic list which i get on run time?

---

<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:** [September 19, 2018, 11:24am UTC](https://discuss.elastic.co/t/in-java-how-to-pass-list-of-indexes-as-paramater-to-search-api/145542/2 "2018-09-19T11:24:37Z")

</div>

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