return 404 when trying to delete a mapping that does not exists
This commit is contained in:
parent
c0f9e337ce
commit
d01048c93d
|
@ -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));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue