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.IndexMissingException;
|
||||||
import org.elasticsearch.indices.IndicesService;
|
import org.elasticsearch.indices.IndicesService;
|
||||||
import org.elasticsearch.indices.InvalidTypeNameException;
|
import org.elasticsearch.indices.InvalidTypeNameException;
|
||||||
|
import org.elasticsearch.indices.TypeMissingException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -228,32 +229,39 @@ public class MetaDataMappingService extends AbstractComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeMapping(final RemoveRequest request, final Listener listener) {
|
public void removeMapping(final RemoveRequest request, final Listener listener) {
|
||||||
|
final AtomicBoolean notifyOnPostProcess = new AtomicBoolean();
|
||||||
clusterService.submitStateUpdateTask("remove-mapping [" + request.mappingType + "]", new ProcessedClusterStateUpdateTask() {
|
clusterService.submitStateUpdateTask("remove-mapping [" + request.mappingType + "]", new ProcessedClusterStateUpdateTask() {
|
||||||
@Override
|
@Override
|
||||||
public ClusterState execute(ClusterState currentState) {
|
public ClusterState execute(ClusterState currentState) {
|
||||||
if (request.indices.length == 0) {
|
if (request.indices.length == 0) {
|
||||||
listener.onFailure(new IndexMissingException(new Index("_all")));
|
listener.onFailure(new IndexMissingException(new Index("_all")));
|
||||||
|
return currentState;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MetaData.Builder builder = newMetaDataBuilder().metaData(currentState.metaData());
|
MetaData.Builder builder = newMetaDataBuilder().metaData(currentState.metaData());
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
String latestIndexWithout = null;
|
||||||
for (String indexName : request.indices) {
|
for (String indexName : request.indices) {
|
||||||
IndexMetaData indexMetaData = currentState.metaData().index(indexName);
|
IndexMetaData indexMetaData = currentState.metaData().index(indexName);
|
||||||
if (indexMetaData != null) {
|
if (indexMetaData != null) {
|
||||||
if (indexMetaData.mappings().containsKey(request.mappingType)) {
|
if (indexMetaData.mappings().containsKey(request.mappingType)) {
|
||||||
builder.put(newIndexMetaDataBuilder(indexMetaData).removeMapping(request.mappingType));
|
builder.put(newIndexMetaDataBuilder(indexMetaData).removeMapping(request.mappingType));
|
||||||
changed = true;
|
changed = true;
|
||||||
|
} else {
|
||||||
|
latestIndexWithout = indexMetaData.index();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!changed) {
|
if (!changed) {
|
||||||
|
listener.onFailure(new TypeMissingException(new Index(latestIndexWithout), request.mappingType));
|
||||||
return currentState;
|
return currentState;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("[{}] remove_mapping [{}]", request.indices, request.mappingType);
|
logger.info("[{}] remove_mapping [{}]", request.indices, request.mappingType);
|
||||||
|
|
||||||
|
notifyOnPostProcess.set(true);
|
||||||
return ClusterState.builder().state(currentState).metaData(builder).build();
|
return ClusterState.builder().state(currentState).metaData(builder).build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
listener.onFailure(e);
|
listener.onFailure(e);
|
||||||
|
@ -263,7 +271,9 @@ public class MetaDataMappingService extends AbstractComponent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clusterStateProcessed(ClusterState clusterState) {
|
public void clusterStateProcessed(ClusterState clusterState) {
|
||||||
listener.onResponse(new Response(true));
|
if (notifyOnPostProcess.get()) {
|
||||||
|
listener.onResponse(new Response(true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue