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

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

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 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****