diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java index 80ac07f3ef1..95675d06e8b 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java @@ -264,7 +264,7 @@ public class MetaDataCreateIndexService extends AbstractComponent { // first, add the default mapping if (mappings.containsKey(MapperService.DEFAULT_MAPPING)) { try { - mapperService.add(MapperService.DEFAULT_MAPPING, XContentFactory.jsonBuilder().map(mappings.get(MapperService.DEFAULT_MAPPING)).string()); + mapperService.add(MapperService.DEFAULT_MAPPING, XContentFactory.jsonBuilder().map(mappings.get(MapperService.DEFAULT_MAPPING)).string(), false); } catch (Exception e) { indicesService.deleteIndex(request.index, "failed on parsing default mapping on index creation"); throw new MapperParsingException("mapping [" + MapperService.DEFAULT_MAPPING + "]", e); @@ -275,7 +275,8 @@ public class MetaDataCreateIndexService extends AbstractComponent { continue; } try { - mapperService.add(entry.getKey(), XContentFactory.jsonBuilder().map(entry.getValue()).string()); + // apply the default here, its the first time we parse it + mapperService.add(entry.getKey(), XContentFactory.jsonBuilder().map(entry.getValue()).string(), true); } catch (Exception e) { indicesService.deleteIndex(request.index, "failed on parsing mappings on index creation"); throw new MapperParsingException("mapping [" + entry.getKey() + "]", e); diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java index e89f4886293..b6ac641f434 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java @@ -119,7 +119,8 @@ public class MetaDataMappingService extends AbstractComponent { for (String type : sTypes) { // only add the current relevant mapping (if exists) if (indexMetaData.mappings().containsKey(type)) { - indexService.mapperService().add(type, indexMetaData.mappings().get(type).source().string()); + // don't apply the default mapping, it has been applied when the mapping was created + indexService.mapperService().add(type, indexMetaData.mappings().get(type).source().string(), false); } } } @@ -176,7 +177,7 @@ public class MetaDataMappingService extends AbstractComponent { createdIndex = true; // only add the current relevant mapping (if exists) if (indexMetaData.mappings().containsKey(type)) { - indexService.mapperService().add(type, indexMetaData.mappings().get(type).source().string()); + indexService.mapperService().add(type, indexMetaData.mappings().get(type).source().string(), false); } } MapperService mapperService = indexService.mapperService(); @@ -304,7 +305,7 @@ public class MetaDataMappingService extends AbstractComponent { indicesToClose.add(indexMetaData.index()); // only add the current relevant mapping (if exists) if (indexMetaData.mappings().containsKey(request.mappingType)) { - indexService.mapperService().add(request.mappingType, indexMetaData.mappings().get(request.mappingType).source().string()); + indexService.mapperService().add(request.mappingType, indexMetaData.mappings().get(request.mappingType).source().string(), false); } } @@ -371,7 +372,8 @@ public class MetaDataMappingService extends AbstractComponent { // we also add it to the registered parsed mapping, since that's what we do when we merge // and, we won't wait for it to be created on this master node IndexService indexService = indicesService.indexService(index); - indexService.mapperService().add(newMapper.type(), newMapper.mappingSource().string()); + // don't apply default mapping, we already applied them when we parsed it + indexService.mapperService().add(newMapper.type(), newMapper.mappingSource().string(), false); if (logger.isDebugEnabled()) { logger.debug("[{}] create_mapping [{}] with source [{}]", index, newMapper.type(), newSource); } else if (logger.isInfoEnabled()) { diff --git a/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 3cf33e0f901..75ebec71a8d 100644 --- a/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -172,7 +172,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable