From 3ff91baedf13711ee3609e2c93f922f85046734d Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 3 Dec 2015 16:06:51 +0100 Subject: [PATCH] Simplify MetaDataMappingService. Now that we create all types on indices that receive a mapping update, creation of temporary indices could get simpler. --- .../metadata/MetaDataMappingService.java | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java index 854d55020dd..5300e69ad95 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java @@ -212,21 +212,14 @@ public class MetaDataMappingService extends AbstractComponent { for (PutMappingClusterStateUpdateRequest request : tasks) { // failures here mean something is broken with our cluster state - fail all tasks by letting exceptions bubble up for (String index : request.indices()) { - if (currentState.metaData().hasIndex(index)) { + final IndexMetaData indexMetaData = currentState.metaData().index(index); + if (indexMetaData != null && indicesService.hasIndex(index) == false) { // if we don't have the index, we will throw exceptions later; - if (indicesService.hasIndex(index) == false || indicesToClose.contains(index)) { - final IndexMetaData indexMetaData = currentState.metaData().index(index); - IndexService indexService; - if (indicesService.hasIndex(index) == false) { - indicesToClose.add(index); - indexService = indicesService.createIndex(nodeServicesProvider, indexMetaData, Collections.emptyList()); - // add mappings for all types, we need them for cross-type validation - for (ObjectCursor mapping : indexMetaData.getMappings().values()) { - indexService.mapperService().merge(mapping.value.type(), mapping.value.source(), false, request.updateAllTypes()); - } - } else { - indexService = indicesService.indexService(index); - } + indicesToClose.add(index); + IndexService indexService = indicesService.createIndex(nodeServicesProvider, indexMetaData, Collections.emptyList()); + // add mappings for all types, we need them for cross-type validation + for (ObjectCursor mapping : indexMetaData.getMappings().values()) { + indexService.mapperService().merge(mapping.value.type(), mapping.value.source(), false, request.updateAllTypes()); } } }