return 404 when trying to delete a mapping that does not exists

This commit is contained in:
Shay Banon 2012-06-25 17:25:19 +02:00
parent c0f9e337ce
commit d01048c93d
1 changed files with 11 additions and 1 deletions

View File

@ -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,8 +271,10 @@ public class MetaDataMappingService extends AbstractComponent {
@Override
public void clusterStateProcessed(ClusterState clusterState) {
if (notifyOnPostProcess.get()) {
listener.onResponse(new Response(true));
}
}
});
}