# Exclude indexes in java search API

**URL:** <https://discuss.elastic.co/t/exclude-indexes-in-java-search-api/117976>\
**Category:** Elasticsearch\
**Created:** [February 1, 2018, 9:07am UTC](https://discuss.elastic.co/t/exclude-indexes-in-java-search-api/117976 "2018-02-01T09:07:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Davidovich1](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@Alex\_Davidovich1](https://discuss.elastic.co/u/Alex_Davidovich1)\
**Post date:** [February 1, 2018, 9:07am UTC](https://discuss.elastic.co/t/exclude-indexes-in-java-search-api/117976/1 "2018-02-01T09:07:24Z")

</div>

Hi,

I am using elasticsearch 5.4.1.  
I create queries using JAVA API and until now we had 5 indexes.  
I always searched all 5 of the indexes and in order to achieve this, I didn't send index names with the search request.  
Now we are going to add a 6 index and now there are 2 usecases:

1. search the 6th index alone - just send its name with the search request.
2. search all indexes excluding the 6th.

I can't give the 5 indexes names hardcoded in the request since they are deleted and created dynamically by the system (with random names).  
So I need to maintain a list of indices in memory and modify this list when it changes in ES.  
I don't like this so much and wanted to have an API in JAVA that can tell ES to search all indexes except the 6th (that has a constant name).  
Can it be done?

Thanks

---

<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 1, 2018, 9:20am UTC](https://discuss.elastic.co/t/exclude-indexes-in-java-search-api/117976/2 "2018-02-01T09:20:06Z")

</div>

I'd use an index template which sets an alias for the new index automatically. Then you just have to query the alias.

---

<div class="post-metadata">

**Author:** ![Alex\_Davidovich1](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@Alex\_Davidovich1](https://discuss.elastic.co/u/Alex_Davidovich1)\
**Post date:** [February 1, 2018, 9:20am UTC](https://discuss.elastic.co/t/exclude-indexes-in-java-search-api/117976/3 "2018-02-01T09:20:43Z")

</div>

Thank you

---

<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 1, 2018, 9:20am UTC](https://discuss.elastic.co/t/exclude-indexes-in-java-search-api/117976/4 "2018-03-01T09:20:44Z")

</div>

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