# Should I wait for a YELLOW status after removing a type?

**URL:** https://discuss.elastic.co/t/should-i-wait-for-a-yellow-status-after-removing-a-type/8208
**Category:** Elasticsearch
**Created:** [June 24, 2012, 4:37pm UTC](https://discuss.elastic.co/t/should-i-wait-for-a-yellow-status-after-removing-a-type/8208 "2012-06-24T16:37:53Z")
**Posts on this page:** 3
**Page:** 1

<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: [June 24, 2012, 4:37pm UTC](https://discuss.elastic.co/t/should-i-wait-for-a-yellow-status-after-removing-a-type/8208/1 "2012-06-24T16:37:53Z")

</div>

Hey All,

Someone raised an issue about the elasticsearch spring factory [1] and I  
can't reproduce it.

So I'm wondering if I need to wait for YELLOW status or to something else  
(sleep 500 for example) after a deleteMapping ?

// Remove mapping and type in ElasticSearch

client.admin().indices()

```
   .prepareDeleteMapping(index)

   .setType(type)

   .execute().actionGet();

```

// Do I need to add this line ?

client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().  
actionGet();

// I'm always getting false here, but the user reports that he's getting  
true and have to add a sleep(500) before lauching isMapping(index, type).

boolean mappingExist = isMappingExist(index, type);

BTW, here is the isMappingExist function:

/\*\*

- Check if a mapping already exists in an index

- @param index Index name

- @param type Mapping name

- @return true if mapping exists

\*/

private boolean isMappingExist(String index, String type) {

```
   ClusterState cs =

```

client.admin().cluster().prepareState().setFilterIndices(index).execute().ac  
tionGet().getState();

```
   IndexMetaData imd = cs.getMetaData().index(index);

   

   if (imd == null) return false;

   MappingMetaData mdd = imd.mapping(type);

   if (mdd != null) return true;

   return false;

```

}

What do you think ? It seems that if the user add the WaitForYellowStatus,  
the problem still occurs. So he really need to add a sleep.

I'm not a great fan of Thread.sleep !

Thanks for your help

David.

[1] [https://github.com/dadoonet/spring-elasticsearch/issues/13](https://github.com/dadoonet/spring-elasticsearch/issues/13)

> <https://github.com/dadoonet/spring-elasticsearch/issues/13>

---

<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: [June 25, 2012, 12:01pm UTC](https://discuss.elastic.co/t/should-i-wait-for-a-yellow-status-after-removing-a-type/8208/2 "2012-06-25T12:01:43Z")

</div>

The delete mapping API does not wait currently until the mapping has been  
deleted on all the other nodes (while others do, btw). I will fix it...

On Sun, Jun 24, 2012 at 6:37 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Hey All,\*\*\*\*
> 
> * * *
> 
> * * *
> 
> Someone raised an issue about the elasticsearch spring factory [1] and I  
> can’t reproduce it.\*\*\*\*
> 
> * * *
> 
> So I’m wondering if I need to wait for YELLOW status or to something else  
> (sleep 500 for example) after a deleteMapping ?\*\*\*\*
> 
> * * *
> 
> // Remove mapping and type in Elasticsearch \*\*\*\*
> 
> client.admin().indices()\*\*\*\*
> 
> ```
> .prepareDeleteMapping(index) ****
> 
> .setType(type) ****
> 
> .execute().actionGet(); ****
> 
> ```
> 
> * * *
> 
> // Do I need to add this line ?\*\*\*\*
> 
> client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> 
> * * *
> 
> * * *
> 
> // I’m always getting false here, but the user reports that he’s getting  
> true and have to add a sleep(500) before lauching isMapping(index, type).\*
> 
> * * *
> 
> _boolean_ mappingExist = isMappingExist(index, type);\*\*\*\*
> 
> * * *
> 
> BTW, here is the isMappingExist function:\*\*\*\*
> 
> * * *
> 
> /\*\*\*\*\*\*
> 
> - Check if a mapping already exists in an index\*\*\*\*
> 
> - _@param_ index Index name\*\*\*\*
> 
> - _@param_ type Mapping name\*\*\*\*
> 
> - _@return_ true if mapping exists\*\*\*\*
> 
> _/_\*\*\*
> 
> _private_ _boolean_ isMappingExist(String index, String type) {\*\*\*\*
> 
> ```
> ClusterState cs = client
> 
> ```
> 
> .admin().cluster().prepareState().setFilterIndices(index).execute().actionGet().getState();
> 
> * * *
> 
> ```
> IndexMetaData imd = cs.getMetaData().index(index); ****
> 
> ****
> 
> *if* (imd == *null*) *return* *false*; ****
> 
> ```
> 
> * * *
> 
> ```
> MappingMetaData mdd = imd.mapping(type); ****
> 
> ```
> 
> * * *
> 
> ```
> *if* (mdd != *null*) *return* *true*; ****
> 
> *return* *false*; ****
> 
> ```
> 
> }\*\*\*\*
> 
> * * *
> 
> What do you think ? It seems that if the user add the WaitForYellowStatus,  
> the problem still occurs. So he really need to add a sleep.\*\*\*\*
> 
> I’m not a great fan of Thread.sleep !\*\*\*\*
> 
> * * *
> 
> Thanks for your help\*\*\*\*
> 
> David.\*\*\*\*
> 
> * * *
> 
> [1] [forceMapping does not work on a multinode cluster · Issue #13 · dadoonet/spring-elasticsearch · GitHub](https://github.com/dadoonet/spring-elasticsearch/issues/13)\*\*\*\*

---

<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:22am UTC](https://discuss.elastic.co/t/should-i-wait-for-a-yellow-status-after-removing-a-type/8208/3 "2017-07-06T03:22:44Z")

</div>


