# Synch wait for index deletion

**URL:** https://discuss.elastic.co/t/synch-wait-for-index-deletion/5508
**Category:** Elasticsearch
**Created:** [October 3, 2011, 9:30pm UTC](https://discuss.elastic.co/t/synch-wait-for-index-deletion/5508 "2011-10-03T21:30:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Steff](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Steff](https://discuss.elastic.co/u/Steff)
#### Post date: [October 3, 2011, 9:30pm UTC](https://discuss.elastic.co/t/synch-wait-for-index-deletion/5508/1 "2011-10-03T21:30:11Z")

</div>

Hi

When we create an index, we wait for the creation to finish before  
continuing. We do the waiting using a health-request with  
waitForYellowStatus on the newly created index. It seems to work fine.

When we delete an index, we would also like to wait for the deletion  
to finish before continuing. We tried using health-request with  
waitForYellowStatus on the deleted index. It seems to me like it is  
not the right way to do it, because it seems like it always take  
exactly 30 secs waiting for yellow status - it smells more like a  
timeout we run into because it might not make sense to check for  
yellow status on a deleted index.

AdminClient admin = client.admin();  
DeleteIndexResponse response =  
admin.indices().delete(Requests.deleteIndexRequest(indexName)).actionGet();  
admin.cluster().health(new  
ClusterHealthRequest(indexName).waitForYellowStatus()).actionGet();

Am I right? How can I wait for the deletion of an index to be finished  
before continuing.

Regards, Per Steffensen

---

<div class="post-metadata">

### Author: ![Steff](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Steff](https://discuss.elastic.co/u/Steff)
#### Post date: [October 4, 2011, 9:54am UTC](https://discuss.elastic.co/t/synch-wait-for-index-deletion/5508/2 "2011-10-04T09:54:43Z")

</div>

Hmmm, this was written directly on google-groups web-page. Why doesnt  
it arrive as a mail on the mailing-list?

On Oct 3, 11:30 pm, Steff [st...@designware.dk](mailto:st...@designware.dk) wrote:

> Hi
> 
> When we create an index, we wait for the creation to finish before  
> continuing. We do the waiting using a health-request with  
> waitForYellowStatus on the newly created index. It seems to work fine.
> 
> When we delete an index, we would also like to wait for the deletion  
> to finish before continuing. We tried using health-request with  
> waitForYellowStatus on the deleted index. It seems to me like it is  
> not the right way to do it, because it seems like it always take  
> exactly 30 secs waiting for yellow status - it smells more like a  
> timeout we run into because it might not make sense to check for  
> yellow status on a deleted index.
> 
> AdminClient admin = client.admin();  
> DeleteIndexResponse response =  
> admin.indices().delete(Requests.deleteIndexRequest(indexName)).actionGet();  
> admin.cluster().health(new  
> ClusterHealthRequest(indexName).waitForYellowStatus()).actionGet();
> 
> Am I right? How can I wait for the deletion of an index to be finished  
> before continuing.
> 
> Regards, Per Steffensen

---

<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: [October 4, 2011, 11:01am UTC](https://discuss.elastic.co/t/synch-wait-for-index-deletion/5508/3 "2011-10-04T11:01:28Z")

</div>

I think there is a misunderstanding here on what waiting for yellow/green  
status means. Let me explain:

When you create an index, the index creation goes to the master node, and  
its handling the actual index creation, adding it to the cluster metadata,  
do initial shard allocation (where the shards should go). It will also wait  
for the index data structure to be created on the relevant nodes shards were  
allocated to (if they are), but won't wait for shards to become started.

Waiting for yellow state after index creation means that are least one shard  
(the primary) from each shard replication group has been started. Waiting  
for green state means that you wait for all shards to be started (including  
replicas).

The cluster health API does not block forever for this state, it waits by  
default for 30s, and if the API has timed out, it is stated in the timed out  
flag.

If you don't wait for yellow status after index creation, it might be ok  
(depends on your usecase). When indexing, the index operation will wait for  
a specific timeout until the primary shard it is designated to work on will  
become available. When searching, it will not wait, but will simply return  
failures for the relevant shards that were not available.

When deleting an index, its not really relevant to wait for yellow status.  
The index has been deleted, there are no shards to wait to become active.  
The delete index will block and wait for the index to be deleted from all  
the nodes that have shards allocated for the relevant index you deleted.

On Mon, Oct 3, 2011 at 11:30 PM, Steff [steff@designware.dk](mailto:steff@designware.dk) wrote:

> Hi
> 
> When we create an index, we wait for the creation to finish before  
> continuing. We do the waiting using a health-request with  
> waitForYellowStatus on the newly created index. It seems to work fine.
> 
> When we delete an index, we would also like to wait for the deletion  
> to finish before continuing. We tried using health-request with  
> waitForYellowStatus on the deleted index. It seems to me like it is  
> not the right way to do it, because it seems like it always take  
> exactly 30 secs waiting for yellow status - it smells more like a  
> timeout we run into because it might not make sense to check for  
> yellow status on a deleted index.
> 
> AdminClient admin = client.admin();  
> DeleteIndexResponse response =  
> admin.indices().delete(Requests.deleteIndexRequest(indexName)).actionGet();  
> admin.cluster().health(new  
> ClusterHealthRequest(indexName).waitForYellowStatus()).actionGet();
> 
> Am I right? How can I wait for the deletion of an index to be finished  
> before continuing.
> 
> Regards, Per Steffensen

---

<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:52am UTC](https://discuss.elastic.co/t/synch-wait-for-index-deletion/5508/4 "2017-07-06T03:52:53Z")

</div>


