# Finding out if an index exists

**URL:** <https://discuss.elastic.co/t/finding-out-if-an-index-exists/3497>\
**Category:** Elasticsearch\
**Created:** [November 1, 2010, 10:12am UTC](https://discuss.elastic.co/t/finding-out-if-an-index-exists/3497 "2010-11-01T10:12:40Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![zohar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zohar/32/3245_2.png) [@zohar](https://discuss.elastic.co/u/zohar)\
**Post date:** [November 1, 2010, 10:12am UTC](https://discuss.elastic.co/t/finding-out-if-an-index-exists/3497/1 "2010-11-01T10:12:40Z")

</div>

Hi  
We have some code to detect if an index exists :

client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(index.name())

is there a slightly more compact/simpler way to do this ?

Cheers  
Z

---

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [November 2, 2010, 8:34pm UTC](https://discuss.elastic.co/t/finding-out-if-an-index-exists/3497/2 "2010-11-02T20:34:48Z")

</div>

We do this:

var establishedIndicies = ;

function initIndex(index) { if (establishedIndicies.contains(index)) {  
return; } try {  
getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();  
} catch(e) { // Index does not exist yet.  
getClient().admin().indices().create(createIndexRequest(index)).actionGet();  
establishedIndicies.push(index); } }

-- jim

On Mon, Nov 1, 2010 at 6:12 AM, zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com) wrote:

> Hi  
> We have some code to detect if an index exists :
> 
> client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(  
> index.name())
> 
> is there a slightly more compact/simpler way to do this ?
> 
> ## Cheers Z
> 
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html](http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [November 2, 2010, 8:35pm UTC](https://discuss.elastic.co/t/finding-out-if-an-index-exists/3497/3 "2010-11-02T20:35:18Z")

</div>

The mail server must be slow. I just got your message now.

-- jim

On Mon, Nov 1, 2010 at 6:12 AM, zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com) wrote:

> Hi  
> We have some code to detect if an index exists :
> 
> client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(  
> index.name())
> 
> is there a slightly more compact/simpler way to do this ?
> 
> ## Cheers Z
> 
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html](http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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:** [November 2, 2010, 9:20pm UTC](https://discuss.elastic.co/t/finding-out-if-an-index-exists/3497/4 "2010-11-02T21:20:55Z")

</div>

The cluster state is the way to do it (preferable over the index status  
API). Use the builder API which is nicer (prepareState()).

On Tue, Nov 2, 2010 at 10:34 PM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com) wrote:

> We do this:
> 
> var establishedIndicies = ;
> 
> function initIndex(index) { if (establishedIndicies.contains(index)) {  
> return; } try {  
> getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();  
> } catch(e) { // Index does not exist yet.  
> getClient().admin().indices().create(createIndexRequest(index)).actionGet();  
> establishedIndicies.push(index); } }
> 
> -- jim
> 
> On Mon, Nov 1, 2010 at 6:12 AM, zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com) wrote:
> 
> > Hi  
> > We have some code to detect if an index exists :
> > 
> > client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(  
> > index.name())
> > 
> > is there a slightly more compact/simpler way to do this ?
> > 
> > ## Cheers Z
> > 
> > View this message in context:  
> > [http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html](http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html)  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Paul\_Loy](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@Paul\_Loy](https://discuss.elastic.co/u/Paul_Loy)\
**Post date:** [November 2, 2010, 11:23pm UTC](https://discuss.elastic.co/t/finding-out-if-an-index-exists/3497/5 "2010-11-02T23:23:56Z")

</div>

I find that if I call this too soon after starting ES my index does not show  
up. Is there any way to determine when the cluster is in a state where it  
knows about the indices, even if it has not yet fully loaded them from a  
gateway?

On Tue, Nov 2, 2010 at 2:20 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> The cluster state is the way to do it (preferable over the index status  
> API). Use the builder API which is nicer (prepareState()).
> 
> On Tue, Nov 2, 2010 at 10:34 PM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com) wrote:
> 
> > We do this:
> > 
> > var establishedIndicies = ;
> > 
> > function initIndex(index) { if (establishedIndicies.contains(index)) {  
> > return; } try {  
> > getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();  
> > } catch(e) { // Index does not exist yet.  
> > getClient().admin().indices().create(createIndexRequest(index)).actionGet();  
> > establishedIndicies.push(index); } }
> > 
> > -- jim
> > 
> > On Mon, Nov 1, 2010 at 6:12 AM, zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com) wrote:
> > 
> > > Hi  
> > > We have some code to detect if an index exists :
> > > 
> > > client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(  
> > > index.name())
> > > 
> > > is there a slightly more compact/simpler way to do this ?
> > > 
> > > ## Cheers Z
> > > 
> > > View this message in context:  
> > > [http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html](http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html)  
> > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

## --

Paul Loy  
[paul@keteracel.com](mailto:paul@keteracel.com)  
[http://uk.linkedin.com/in/paulloy](http://uk.linkedin.com/in/paulloy)

---

<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:** [November 2, 2010, 11:38pm UTC](https://discuss.elastic.co/t/finding-out-if-an-index-exists/3497/6 "2010-11-02T23:38:11Z")

</div>

Use the cluster state API, its the first thing that gets recovered from the  
gateway. While it has not recovered yet, its is in a blocked state, and you  
can check that by using ClusterState#getBlocks() and verifying that there  
are no global blocks.

Another option to wait for the cluster to recover is the use the cluster  
health API, with all the different waitFor options. Waiting for a yellow  
status on a specific index or across all indices.

-shay.banon

On Wed, Nov 3, 2010 at 1:23 AM, Paul Loy [keteracel@gmail.com](mailto:keteracel@gmail.com) wrote:

> I find that if I call this too soon after starting ES my index does not  
> show up. Is there any way to determine when the cluster is in a state where  
> it knows about the indices, even if it has not yet fully loaded them from a  
> gateway?
> 
> On Tue, Nov 2, 2010 at 2:20 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> > The cluster state is the way to do it (preferable over the index status  
> > API). Use the builder API which is nicer (prepareState()).
> > 
> > On Tue, Nov 2, 2010 at 10:34 PM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com)wrote:
> > 
> > > We do this:
> > > 
> > > var establishedIndicies = ;
> > > 
> > > function initIndex(index) { if (establishedIndicies.contains(index)) {  
> > > return; } try {  
> > > getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();  
> > > } catch(e) { // Index does not exist yet.  
> > > getClient().admin().indices().create(createIndexRequest(index)).actionGet();  
> > > establishedIndicies.push(index); } }
> > > 
> > > -- jim
> > > 
> > > On Mon, Nov 1, 2010 at 6:12 AM, zohar [zohar.melamed@gmail.com](mailto:zohar.melamed@gmail.com) wrote:
> > > 
> > > > Hi  
> > > > We have some code to detect if an index exists :
> > > > 
> > > > client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(  
> > > > index.name())
> > > > 
> > > > is there a slightly more compact/simpler way to do this ?
> > > > 
> > > > ## Cheers Z
> > > > 
> > > > View this message in context:  
> > > > [http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html](http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html)  
> > > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> ## --
> 
> Paul Loy  
> [paul@keteracel.com](mailto:paul@keteracel.com)  
> [Paul Loy - Amihan Entertainment | LinkedIn](http://uk.linkedin.com/in/paulloy)

---

<div class="post-metadata">

**Author:** ![Christian\_Pesch](https://avatars.discourse-cdn.com/v4/letter/c/e95f7d/32.png) [@Christian\_Pesch](https://discuss.elastic.co/u/Christian_Pesch)\
**Post date:** [November 15, 2010, 4:47pm UTC](https://discuss.elastic.co/t/finding-out-if-an-index-exists/3497/7 "2010-11-15T16:47:47Z")

</div>

Hi Shay,

I've stumbled across a problem with 0.12.1 and node.local=true when  
checking for the existance of an index.  
I'm using the sequence

client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();  
ClusterStateResponse response =  
client.admin().cluster().prepareState().execute().actionGet();  
boolean hasIndex =  
response.getState().metaData().hasIndex(indexName);  
if(!hasIndex)

client.admin().indices().create(createIndexRequest(indexName)).actionGet();

This works fine when I set discovery.zen.ping.unicast.hosts but fails  
1 or 2 times out of 10 when setting  
node.local=true. Then setWaitForYellowStatus() does not guarantee that  
all indices are known and  
the hasIndex() returns false although the index exists (and is visible  
after a few more seconds).  
Is this a known problem?

Kind regards  
Christian

On Nov 2, 10:20 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> The cluster state is the way to do it (preferable over the index status  
> API). Use the builder API which is nicer (prepareState()).
> 
> On Tue, Nov 2, 2010 at 10:34 PM, James Cook [jc...@tracermedia.com](mailto:jc...@tracermedia.com) wrote:
> 
> > We do this:
> 
> > var establishedIndicies = ;
> 
> > function initIndex(index) { if (establishedIndicies.contains(index)) {  
> > return; } try {  
> > getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();  
> > } catch(e) { // Index does not exist yet.  
> > getClient().admin().indices().create(createIndexRequest(index)).actionGet();  
> > establishedIndicies.push(index); } }
> 
> > -- jim
> 
> > On Mon, Nov 1, 2010 at 6:12 AM, zohar [zohar.mela...@gmail.com](mailto:zohar.mela...@gmail.com) wrote:
> 
> > > Hi  
> > > We have some code to detect if an index exists :
> 
> > > client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(  
> > > index.name())
> 
> > > is there a slightly more compact/simpler way to do this ?
> 
> > > ## Cheers Z
> > > 
> > > View this message in context:  
> > > [http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-ind](http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-ind)...  
> > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![zohar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zohar/32/3245_2.png) [@zohar](https://discuss.elastic.co/u/zohar)\
**Post date:** [November 15, 2010, 4:50pm UTC](https://discuss.elastic.co/t/finding-out-if-an-index-exists/3497/8 "2010-11-15T16:50:00Z")

</div>

We have the very same problem

---

<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:** [November 15, 2010, 4:57pm UTC](https://discuss.elastic.co/t/finding-out-if-an-index-exists/3497/9 "2010-11-15T16:57:00Z")

</div>

This should be fixed in master (0.13), can you give it a go?

On Mon, Nov 15, 2010 at 6:47 PM, Christian Pesch [cpesch@gmail.com](mailto:cpesch@gmail.com) wrote:

> Hi Shay,
> 
> I've stumbled across a problem with 0.12.1 and node.local=true when  
> checking for the existance of an index.  
> I'm using the sequence
> 
> client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();  
> ClusterStateResponse response =  
> client.admin().cluster().prepareState().execute().actionGet();  
> boolean hasIndex =  
> response.getState().metaData().hasIndex(indexName);  
> if(!hasIndex)
> 
> client.admin().indices().create(createIndexRequest(indexName)).actionGet();
> 
> This works fine when I set discovery.zen.ping.unicast.hosts but fails  
> 1 or 2 times out of 10 when setting  
> node.local=true. Then setWaitForYellowStatus() does not guarantee that  
> all indices are known and  
> the hasIndex() returns false although the index exists (and is visible  
> after a few more seconds).  
> Is this a known problem?
> 
> Kind regards  
> Christian
> 
> On Nov 2, 10:20 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > The cluster state is the way to do it (preferable over the index status  
> > API). Use the builder API which is nicer (prepareState()).
> > 
> > On Tue, Nov 2, 2010 at 10:34 PM, James Cook [jc...@tracermedia.com](mailto:jc...@tracermedia.com)  
> > wrote:
> > 
> > > We do this:
> > 
> > > var establishedIndicies = ;
> > 
> > > function initIndex(index) { if (establishedIndicies.contains(index)) {  
> > > return; } try {
> 
> getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();
> 
> > > } catch(e) { // Index does not exist yet.
> 
> getClient().admin().indices().create(createIndexRequest(index)).actionGet();
> 
> > > establishedIndicies.push(index); } }
> > 
> > > -- jim
> > 
> > > On Mon, Nov 1, 2010 at 6:12 AM, zohar [zohar.mela...@gmail.com](mailto:zohar.mela...@gmail.com) wrote:
> > 
> > > > Hi  
> > > > We have some code to detect if an index exists :
> > 
> > > >
> 
> client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(
> 
> > > > index.name())
> > 
> > > > is there a slightly more compact/simpler way to do this ?
> > 
> > > > ## Cheers Z
> > > > 
> > > > View this message in context:  
> > > > [http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-ind](http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-ind).  
> > > > ..  
> > > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Christian\_Pesch](https://avatars.discourse-cdn.com/v4/letter/c/e95f7d/32.png) [@Christian\_Pesch](https://discuss.elastic.co/u/Christian_Pesch)\
**Post date:** [November 15, 2010, 5:27pm UTC](https://discuss.elastic.co/t/finding-out-if-an-index-exists/3497/10 "2010-11-15T17:27:07Z")

</div>

Great! The error didn't occur on 15 startups, it seems to be gone.  
Are you going to release 0.13.0 at the end of November?

On Nov 15, 5:57 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> This should be fixed in master (0.13), can you give it a go?
> 
> On Mon, Nov 15, 2010 at 6:47 PM, Christian Pesch [cpe...@gmail.com](mailto:cpe...@gmail.com) wrote:
> 
> > Hi Shay,
> 
> > I've stumbled across a problem with 0.12.1 and node.local=true when  
> > checking for the existance of an index.  
> > I'm using the sequence
> 
> > client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();  
> > ClusterStateResponse response =  
> > client.admin().cluster().prepareState().execute().actionGet();  
> > boolean hasIndex =  
> > response.getState().metaData().hasIndex(indexName);  
> > if(!hasIndex)
> 
> > client.admin().indices().create(createIndexRequest(indexName)).actionGet();
> 
> > This works fine when I set discovery.zen.ping.unicast.hosts but fails  
> > 1 or 2 times out of 10 when setting  
> > node.local=true. Then setWaitForYellowStatus() does not guarantee that  
> > all indices are known and  
> > the hasIndex() returns false although the index exists (and is visible  
> > after a few more seconds).  
> > Is this a known problem?
> 
> > Kind regards  
> > Christian
> 
> > On Nov 2, 10:20 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > 
> > > The cluster state is the way to do it (preferable over the index status  
> > > API). Use the builder API which is nicer (prepareState()).
> 
> > > On Tue, Nov 2, 2010 at 10:34 PM, James Cook [jc...@tracermedia.com](mailto:jc...@tracermedia.com)  
> > > wrote:
> > > 
> > > > We do this:
> 
> > > > var establishedIndicies = ;
> 
> > > > function initIndex(index) { if (establishedIndicies.contains(index)) {  
> > > > return; } try {
> 
> > getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();
> > 
> > > > } catch(e) { // Index does not exist yet.
> 
> > getClient().admin().indices().create(createIndexRequest(index)).actionGet();
> > 
> > > > establishedIndicies.push(index); } }
> 
> > > > -- jim
> 
> > > > On Mon, Nov 1, 2010 at 6:12 AM, zohar [zohar.mela...@gmail.com](mailto:zohar.mela...@gmail.com) wrote:
> 
> > > > > Hi  
> > > > > We have some code to detect if an index exists :
> 
> > client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(
> > 
> > > > > index.name())
> 
> > > > > is there a slightly more compact/simpler way to do this ?
> 
> > > > > ## Cheers Z
> > > > > 
> > > > > View this message in context:  
> > > > > [http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-ind](http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-ind).  
> > > > > ..  
> > > > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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:** [November 15, 2010, 5:32pm UTC](https://discuss.elastic.co/t/finding-out-if-an-index-exists/3497/11 "2010-11-15T17:32:37Z")

</div>

0.13 will be released this week :), finalizing things now and running the  
"long running" regression tests...

On Mon, Nov 15, 2010 at 7:27 PM, Christian Pesch [cpesch@gmail.com](mailto:cpesch@gmail.com) wrote:

> Great! The error didn't occur on 15 startups, it seems to be gone.  
> Are you going to release 0.13.0 at the end of November?
> 
> On Nov 15, 5:57 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > This should be fixed in master (0.13), can you give it a go?
> > 
> > On Mon, Nov 15, 2010 at 6:47 PM, Christian Pesch [cpe...@gmail.com](mailto:cpe...@gmail.com)  
> > wrote:
> > 
> > > Hi Shay,
> > 
> > > I've stumbled across a problem with 0.12.1 and node.local=true when  
> > > checking for the existance of an index.  
> > > I'm using the sequence
> > 
> > >
> 
> client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> 
> > > ```
> > > ClusterStateResponse response =
> > > 
> > > ```
> > > 
> > > client.admin().cluster().prepareState().execute().actionGet();  
> > > boolean hasIndex =  
> > > response.getState().metaData().hasIndex(indexName);  
> > > if(!hasIndex)
> > 
> > >
> 
> client.admin().indices().create(createIndexRequest(indexName)).actionGet();
> 
> > > This works fine when I set discovery.zen.ping.unicast.hosts but fails  
> > > 1 or 2 times out of 10 when setting  
> > > node.local=true. Then setWaitForYellowStatus() does not guarantee that  
> > > all indices are known and  
> > > the hasIndex() returns false although the index exists (and is visible  
> > > after a few more seconds).  
> > > Is this a known problem?
> > 
> > > Kind regards  
> > > Christian
> > 
> > > On Nov 2, 10:20 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > > 
> > > > The cluster state is the way to do it (preferable over the index  
> > > > status  
> > > > API). Use the builder API which is nicer (prepareState()).
> > 
> > > > On Tue, Nov 2, 2010 at 10:34 PM, James Cook [jc...@tracermedia.com](mailto:jc...@tracermedia.com)  
> > > > wrote:
> > > > 
> > > > > We do this:
> > 
> > > > > var establishedIndicies = ;
> > 
> > > > > function initIndex(index) { if  
> > > > > (establishedIndicies.contains(index)) {  
> > > > > return; } try {
> > 
> > >
> 
> getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();
> 
> > > > > } catch(e) { // Index does not exist yet.
> > 
> > >
> 
> getClient().admin().indices().create(createIndexRequest(index)).actionGet();
> 
> > > > > establishedIndicies.push(index); } }
> > 
> > > > > -- jim
> > 
> > > > > On Mon, Nov 1, 2010 at 6:12 AM, zohar [zohar.mela...@gmail.com](mailto:zohar.mela...@gmail.com)  
> > > > > wrote:
> > 
> > > > > > Hi  
> > > > > > We have some code to detect if an index exists :
> > 
> > >
> 
> client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(
> 
> > > > > > index.name())
> > 
> > > > > > is there a slightly more compact/simpler way to do this ?
> > 
> > > > > > ## Cheers Z
> > > > > > 
> > > > > > View this message in context:
> 
> [http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-ind](http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-ind).
> 
> > > ..
> > > 
> > > > > > Sent from the Elasticsearch Users mailing list archive at  
> > > > > > [Nabble.com](http://Nabble.com).

---

<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, 4:16am UTC](https://discuss.elastic.co/t/finding-out-if-an-index-exists/3497/12 "2017-07-06T04:16:30Z")

</div>


