diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java index cfa47396efd..e89f4886293 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java @@ -41,6 +41,7 @@ import org.elasticsearch.index.service.IndexService; import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.InvalidTypeNameException; +import org.elasticsearch.indices.TypeMissingException; import java.io.IOException; import java.util.Arrays; @@ -228,32 +229,39 @@ public class MetaDataMappingService extends AbstractComponent { } public void removeMapping(final RemoveRequest request, final Listener listener) { + final AtomicBoolean notifyOnPostProcess = new AtomicBoolean(); clusterService.submitStateUpdateTask("remove-mapping [" + request.mappingType + "]", new ProcessedClusterStateUpdateTask() { @Override public ClusterState execute(ClusterState currentState) { if (request.indices.length == 0) { listener.onFailure(new IndexMissingException(new Index("_all"))); + return currentState; } try { MetaData.Builder builder = newMetaDataBuilder().metaData(currentState.metaData()); boolean changed = false; + String latestIndexWithout = null; for (String indexName : request.indices) { IndexMetaData indexMetaData = currentState.metaData().index(indexName); if (indexMetaData != null) { if (indexMetaData.mappings().containsKey(request.mappingType)) { builder.put(newIndexMetaDataBuilder(indexMetaData).removeMapping(request.mappingType)); changed = true; + } else { + latestIndexWithout = indexMetaData.index(); } } } if (!changed) { + listener.onFailure(new TypeMissingException(new Index(latestIndexWithout), request.mappingType)); return currentState; } logger.info("[{}] remove_mapping [{}]", request.indices, request.mappingType); + notifyOnPostProcess.set(true); return ClusterState.builder().state(currentState).metaData(builder).build(); } catch (Exception e) { listener.onFailure(e); @@ -263,7 +271,9 @@ public class MetaDataMappingService extends AbstractComponent { @Override public void clusterStateProcessed(ClusterState clusterState) { - listener.onResponse(new Response(true)); + if (notifyOnPostProcess.get()) { + listener.onResponse(new Response(true)); + } } }); }