# How to get index is exist in elastic cluster?

**URL:** <https://discuss.elastic.co/t/how-to-get-index-is-exist-in-elastic-cluster/5256>\
**Category:** Elasticsearch\
**Created:** [August 26, 2011, 6:42am UTC](https://discuss.elastic.co/t/how-to-get-index-is-exist-in-elastic-cluster/5256 "2011-08-26T06:42:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_4](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sam\_4](https://discuss.elastic.co/u/Sam_4)\
**Post date:** [August 26, 2011, 6:42am UTC](https://discuss.elastic.co/t/how-to-get-index-is-exist-in-elastic-cluster/5256/1 "2011-08-26T06:42:55Z")

</div>

Hi

I Have situation where i want to delete index from cluster.before i  
need to check the availability of index in elastic server.if it  
available then go for delete an index.please tell me how to get the  
index exist in cluster using elastic java library.

Thanks

---

<div class="post-metadata">

**Author:** ![Kun\_Niu](https://avatars.discourse-cdn.com/v4/letter/k/8c91f0/32.png) [@Kun\_Niu](https://discuss.elastic.co/u/Kun_Niu)\
**Post date:** [August 26, 2011, 7:04am UTC](https://discuss.elastic.co/t/how-to-get-index-is-exist-in-elastic-cluster/5256/2 "2011-08-26T07:04:17Z")

</div>

You can try to IndicesExistsRequest and IndicesExistsResponse to verify  
that.  
You can build the request using IndicesAdminClient.  
I had ever used it and it worked for me.

> -----Original Message-----  
> From: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] On Behalf Of sam  
> Sent: 2011年8月26日 14:43  
> To: elasticsearch  
> Subject: how to get index is exist in elastic cluster?
> 
> Hi
> 
> I Have situation where i want to delete index from cluster.before i need  
> to  
> check the availability of index in elastic server.if it available then go  
> for delete  
> an index.please tell me how to get the index exist in cluster using  
> elastic java  
> library.
> 
> 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:** [August 26, 2011, 7:04am UTC](https://discuss.elastic.co/t/how-to-get-index-is-exist-in-elastic-cluster/5256/3 "2011-08-26T07:04:45Z")

</div>

You can also delete the index and only catch the IndexMissingException.

David 😉

Le 26 août 2011 à 08:42, sam [mishra.sameek@gmail.com](mailto:mishra.sameek@gmail.com) a écrit :

> Hi
> 
> I Have situation where i want to delete index from cluster.before i  
> need to check the availability of index in elastic server.if it  
> available then go for delete an index.please tell me how to get the  
> index exist in cluster using elastic java library.
> 
> Thanks

---

<div class="post-metadata">

**Author:** ![Kun\_Niu](https://avatars.discourse-cdn.com/v4/letter/k/8c91f0/32.png) [@Kun\_Niu](https://discuss.elastic.co/u/Kun_Niu)\
**Post date:** [August 26, 2011, 7:06am UTC](https://discuss.elastic.co/t/how-to-get-index-is-exist-in-elastic-cluster/5256/4 "2011-08-26T07:06:09Z")

</div>

Just pay attention that it is a remote exception.

> -----Original Message-----  
> From: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] On Behalf Of David Pilato  
> Sent: 2011年8月26日 15:05  
> To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> Subject: Re: how to get index is exist in elastic cluster?
> 
> You can also delete the index and only catch the IndexMissingException.
> 
> David 😉
> 
> Le 26 août 2011 à 08:42, sam [mishra.sameek@gmail.com](mailto:mishra.sameek@gmail.com) a écrit :
> 
> > Hi
> > 
> > I Have situation where i want to delete index from cluster.before i  
> > need to check the availability of index in elastic server.if it  
> > available then go for delete an index.please tell me how to get the  
> > index exist in cluster using elastic java library.
> > 
> > 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:** [August 26, 2011, 4:21pm UTC](https://discuss.elastic.co/t/how-to-get-index-is-exist-in-elastic-cluster/5256/5 "2011-08-26T16:21:29Z")

</div>

I'm sorry I have to disagree.

Here is what I wrote to force delete an index.

```
	try {
		node.client().admin().indices()
				.delete(new DeleteIndexRequest("myindexname")).actionGet();
	} catch (IndexMissingException e) {
		// Index does not exist... Fine
	}

```

As you can see, I catch the IndexMissingException which grand grand grand parent is a RuntimeException.

David.

-----Message d'origine-----  
De : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com) [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] De la part de Kun Niu  
Envoyé : vendredi 26 août 2011 09:06  
À : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
Objet : RE: how to get index is exist in elastic cluster?

Just pay attention that it is a remote exception.

> -----Original Message-----  
> From: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] On Behalf Of David Pilato  
> Sent: 2011年8月26日 15:05  
> To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> Subject: Re: how to get index is exist in elastic cluster?
> 
> You can also delete the index and only catch the IndexMissingException.
> 
> David 😉
> 
> Le 26 août 2011 à 08:42, sam [mishra.sameek@gmail.com](mailto:mishra.sameek@gmail.com) a écrit :
> 
> > Hi
> > 
> > I Have situation where i want to delete index from cluster.before i  
> > need to check the availability of index in elastic server.if it  
> > available then go for delete an index.please tell me how to get the  
> > index exist in cluster using elastic java library.
> > 
> > Thanks

---

<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:** [August 26, 2011, 8:54pm UTC](https://discuss.elastic.co/t/how-to-get-index-is-exist-in-elastic-cluster/5256/6 "2011-08-26T20:54:28Z")

</div>

You might get it wrapped in a RemoteException as well, if it ended up coming  
from another node. The remove exception thingy is very handy when it comes  
to debugging (has a trace of all the nodes that the failure came from), but,  
it does not work amazingly well with java catch clauses... .

On Fri, Aug 26, 2011 at 7:21 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> I'm sorry I have to disagree.
> 
> Here is what I wrote to force delete an index.
> 
> ```
> try {
> node.client().admin().indices()
> .delete(new
> 
> ```
> 
> DeleteIndexRequest("myindexname")).actionGet();  
> } catch (IndexMissingException e) {  
> // Index does not exist... Fine  
> }
> 
> As you can see, I catch the IndexMissingException which grand grand grand  
> parent is a RuntimeException.
> 
> David.
> 
> -----Message d'origine-----  
> De : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com) [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)]  
> De la part de Kun Niu  
> Envoyé : vendredi 26 août 2011 09:06  
> À : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> Objet : RE: how to get index is exist in elastic cluster?
> 
> Just pay attention that it is a remote exception.
> 
> > -----Original Message-----  
> > From: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> > [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] On Behalf Of David Pilato  
> > Sent: 2011年8月26日 15:05  
> > To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> > Subject: Re: how to get index is exist in elastic cluster?
> > 
> > You can also delete the index and only catch the IndexMissingException.
> > 
> > David 😉
> > 
> > Le 26 août 2011 à 08:42, sam [mishra.sameek@gmail.com](mailto:mishra.sameek@gmail.com) a écrit :
> > 
> > > Hi
> > > 
> > > I Have situation where i want to delete index from cluster.before i  
> > > need to check the availability of index in elastic server.if it  
> > > available then go for delete an index.please tell me how to get the  
> > > index exist in cluster using elastic java library.
> > > 
> > > Thanks

---

<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:55am UTC](https://discuss.elastic.co/t/how-to-get-index-is-exist-in-elastic-cluster/5256/7 "2017-07-06T03:55:51Z")

</div>


