# PrepareSearch in selected Indices

**URL:** <https://discuss.elastic.co/t/preparesearch-in-selected-indices/7123>\
**Category:** Elasticsearch\
**Created:** [March 26, 2012, 10:25am UTC](https://discuss.elastic.co/t/preparesearch-in-selected-indices/7123 "2012-03-26T10:25:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)\
**Post date:** [March 26, 2012, 10:25am UTC](https://discuss.elastic.co/t/preparesearch-in-selected-indices/7123/1 "2012-03-26T10:25:14Z")

</div>

Hi,

I have the indices namely 1990, 2000, 2006 and Variance in a same  
Folder. Here Variance Index is different Json.

How can I search only 1990, 2000, 2006 Index alone and not using  
the Index Variance using prepareSearch?

I am using the code:

SearchRequestBuilder searchRequestBuilder = client.prepareSearch(" ");  
searchRequestBuilder.setSearchType(SearchType.QUERY\_THEN\_FETCH);  
response = searchRequestBuilder.execute().actionGet();

Cheers!!

George

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 27, 2012, 1:07pm UTC](https://discuss.elastic.co/t/preparesearch-in-selected-indices/7123/2 "2012-03-27T13:07:30Z")

</div>

prepareSearch("1990", "2000", "2006")....

On Mon, Mar 26, 2012 at 12:25 PM, George Viju [vijuitech@gmail.com](mailto:vijuitech@gmail.com) wrote:

> Hi,
> 
> I have the indices namely 1990, 2000, 2006 and Variance in a same  
> Folder. Here Variance Index is different Json.
> 
> How can I search only 1990, 2000, 2006 Index alone and not using  
> the Index Variance using prepareSearch?
> 
> I am using the code:
> 
> SearchRequestBuilder searchRequestBuilder = client.prepareSearch(" ");  
> searchRequestBuilder.setSearchType(SearchType.QUERY\_THEN\_FETCH);  
> response = searchRequestBuilder.execute().actionGet();
> 
> Cheers!!
> 
> George

---

<div class="post-metadata">

**Author:** ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)\
**Post date:** [March 28, 2012, 3:59am UTC](https://discuss.elastic.co/t/preparesearch-in-selected-indices/7123/3 "2012-03-28T03:59:42Z")

</div>

Thanks Shay....

If in future it may create 2007,2008... indices, Is there any other  
way to select and search the indices dynamically? Is there any other  
method to search the Indices dynamically ignoring the Variance Index?  
Is there any other method to find the indices(to check what are the  
indices available) in the in the indices folder?

Thanks!!

George

On Mar 27, 6:07 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> prepareSearch("1990", "2000", "2006")....
> 
> On Mon, Mar 26, 2012 at 12:25 PM, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> 
> > Hi,
> 
> > I have the indices namely 1990, 2000, 2006 and Variance in a same  
> > Folder. Here Variance Index is different Json.
> 
> > How can I search only 1990, 2000, 2006 Index alone and not using  
> > the Index Variance using prepareSearch?
> 
> > I am using the code:
> 
> > SearchRequestBuilder searchRequestBuilder = client.prepareSearch(" ");  
> > searchRequestBuilder.setSearchType(SearchType.QUERY\_THEN\_FETCH);  
> > response = searchRequestBuilder.execute().actionGet();
> 
> > Cheers!!
> 
> > George

---

<div class="post-metadata">

**Author:** ![Thomas\_Peuss](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@Thomas\_Peuss](https://discuss.elastic.co/u/Thomas_Peuss)\
**Post date:** [March 28, 2012, 6:59am UTC](https://discuss.elastic.co/t/preparesearch-in-selected-indices/7123/4 "2012-03-28T06:59:45Z")

</div>

Hi George!

Am Mittwoch, 28. März 2012 05:59:42 UTC+2 schrieb George Viju:

> If in future it may create 2007,2008... indices, Is there any other  
> way to select and search the indices dynamically? Is there any other  
> method to search the Indices dynamically ignoring the Variance Index?  
> Is there any other method to find the indices(to check what are the  
> indices available) in the in the indices folder?

You can use curl -XGET '[http://localhost:9200/\_status](http://localhost:9200/_status)' to get the list of  
all indices that exist...

CU  
Thomas

---

<div class="post-metadata">

**Author:** ![Thomas\_Peuss](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@Thomas\_Peuss](https://discuss.elastic.co/u/Thomas_Peuss)\
**Post date:** [March 28, 2012, 7:01am UTC](https://discuss.elastic.co/t/preparesearch-in-selected-indices/7123/5 "2012-03-28T07:01:21Z")

</div>

Hi George!

Am Mittwoch, 28. März 2012 05:59:42 UTC+2 schrieb George Viju:

> Thanks Shay....
> 
> If in future it may create 2007,2008... indices, Is there any other  
> way to select and search the indices dynamically? Is there any other  
> method to search the Indices dynamically ignoring the Variance Index?  
> Is there any other method to find the indices(to check what are the  
> indices available) in the in the indices folder?

In Java-Code:  
IndicesStatusRequestBuilder  
isrb=ElasticSearchController.getClient().admin().indices().prepareStatus();  
IndicesStatusResponse rsp=isrb.execute().actionGet();

```
    List<String> response=new ArrayList<String>();
    for (String indexName : rsp.indices().keySet()) {
        response.add(indexName);
    }
    Collections.sort(response);
    return response;

```

CU  
Thomas

---

<div class="post-metadata">

**Author:** ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)\
**Post date:** [March 28, 2012, 7:25am UTC](https://discuss.elastic.co/t/preparesearch-in-selected-indices/7123/6 "2012-03-28T07:25:27Z")

</div>

Thank you so much Thomas!!

Cheers!!

George

On Mar 28, 12:01 pm, Thomas Peuss [thomas.pe...@nterra.com](mailto:thomas.pe...@nterra.com) wrote:

> Hi George!
> 
> Am Mittwoch, 28. März 2012 05:59:42 UTC+2 schrieb George Viju:
> 
> > Thanks Shay....
> 
> > If in future it may create 2007,2008... indices, Is there any other  
> > way to select and search the indices dynamically? Is there any other  
> > method to search the Indices dynamically ignoring the Variance Index?  
> > Is there any other method to find the indices(to check what are the  
> > indices available) in the in the indices folder?
> 
> In Java-Code:  
> IndicesStatusRequestBuilder  
> isrb=ElasticSearchController.getClient().admin().indices().prepareStatus();  
> IndicesStatusResponse rsp=isrb.execute().actionGet();
> 
> ```
> List<String> response=new ArrayList<String>();
> for (String indexName : rsp.indices().keySet()) {
> response.add(indexName);
> }
> Collections.sort(response);
> return response;
> 
> ```
> 
> CU  
> Thomas

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 28, 2012, 8:56am UTC](https://discuss.elastic.co/t/preparesearch-in-selected-indices/7123/7 "2012-03-28T08:56:04Z")

</div>

I don't recommend using the status request to get the list of indices, use  
the cluster state API, its more lightweight.

On Wed, Mar 28, 2012 at 9:25 AM, George Viju [vijuitech@gmail.com](mailto:vijuitech@gmail.com) wrote:

> Thank you so much Thomas!!
> 
> Cheers!!
> 
> George
> 
> On Mar 28, 12:01 pm, Thomas Peuss [thomas.pe...@nterra.com](mailto:thomas.pe...@nterra.com) wrote:
> 
> > Hi George!
> > 
> > Am Mittwoch, 28. März 2012 05:59:42 UTC+2 schrieb George Viju:
> > 
> > > Thanks Shay....
> > 
> > > If in future it may create 2007,2008... indices, Is there any other  
> > > way to select and search the indices dynamically? Is there any other  
> > > method to search the Indices dynamically ignoring the Variance Index?  
> > > Is there any other method to find the indices(to check what are the  
> > > indices available) in the in the indices folder?
> > 
> > In Java-Code:  
> > IndicesStatusRequestBuilder
> 
> isrb=ElasticSearchController.getClient().admin().indices().prepareStatus();
> 
> > ```
> > IndicesStatusResponse rsp=isrb.execute().actionGet();
> > 
> > List<String> response=new ArrayList<String>();
> > for (String indexName : rsp.indices().keySet()) {
> > response.add(indexName);
> > }
> > Collections.sort(response);
> > return response;
> > 
> > ```
> > 
> > CU  
> > Thomas

---

<div class="post-metadata">

**Author:** ![vijuitech](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vijuitech](https://discuss.elastic.co/u/vijuitech)\
**Post date:** [March 28, 2012, 12:52pm UTC](https://discuss.elastic.co/t/preparesearch-in-selected-indices/7123/8 "2012-03-28T12:52:22Z")

</div>

ok. Thank you so much Shay!

cheers!

George

On Mar 28, 1:56 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> I don't recommend using the status request to get the list of indices, use  
> the cluster state API, its more lightweight.
> 
> On Wed, Mar 28, 2012 at 9:25 AM, George Viju [vijuit...@gmail.com](mailto:vijuit...@gmail.com) wrote:
> 
> > Thank you so much Thomas!!
> 
> > Cheers!!
> 
> > George
> 
> > On Mar 28, 12:01 pm, Thomas Peuss [thomas.pe...@nterra.com](mailto:thomas.pe...@nterra.com) wrote:
> > 
> > > Hi George!
> 
> > > Am Mittwoch, 28. März 2012 05:59:42 UTC+2 schrieb George Viju:
> 
> > > > Thanks Shay....
> 
> > > > If in future it may create 2007,2008... indices, Is there any other  
> > > > way to select and search the indices dynamically? Is there any other  
> > > > method to search the Indices dynamically ignoring the Variance Index?  
> > > > Is there any other method to find the indices(to check what are the  
> > > > indices available) in the in the indices folder?
> 
> > > In Java-Code:  
> > > IndicesStatusRequestBuilder
> 
> > isrb=ElasticSearchController.getClient().admin().indices().prepareStatus();
> > 
> > > ```
> > > IndicesStatusResponse rsp=isrb.execute().actionGet();
> > > 
> > > ```
> 
> > > ```
> > > List<String> response=new ArrayList<String>();
> > > for (String indexName : rsp.indices().keySet()) {
> > > response.add(indexName);
> > > }
> > > Collections.sort(response);
> > > return response;
> > > 
> > > ```
> 
> > > CU  
> > > Thomas

---

<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 6, 2017, 3:34am UTC](https://discuss.elastic.co/t/preparesearch-in-selected-indices/7123/9 "2017-07-06T03:34:21Z")

</div>


