From 1fa960962711a2c540e12fbbc2f93c4c1ace2dcb Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Tue, 12 Sep 2017 15:25:43 +0200 Subject: [PATCH 1/2] Remove MapperService#dynamic. We ignore it as of 6.0 and forbid it as of 7.0. --- .../index/mapper/MapperService.java | 32 ++++--------------- .../mapper/DynamicMappingVersionTests.java | 13 -------- 2 files changed, 7 insertions(+), 38 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java index c9851ed7a1d05..04ee7e53ef1b9 100755 --- a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -50,7 +50,6 @@ import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.indices.InvalidTypeNameException; -import org.elasticsearch.indices.TypeMissingException; import org.elasticsearch.indices.mapper.MapperRegistry; import java.io.Closeable; @@ -99,7 +98,8 @@ public enum MergeReason { Setting.longSetting("index.mapping.depth.limit", 20L, 1, Property.Dynamic, Property.IndexScope); public static final boolean INDEX_MAPPER_DYNAMIC_DEFAULT = true; public static final Setting INDEX_MAPPER_DYNAMIC_SETTING = - Setting.boolSetting("index.mapper.dynamic", INDEX_MAPPER_DYNAMIC_DEFAULT, Property.Dynamic, Property.IndexScope); + Setting.boolSetting("index.mapper.dynamic", INDEX_MAPPER_DYNAMIC_DEFAULT, + Property.Dynamic, Property.IndexScope, Property.Deprecated); private static ObjectHashSet META_FIELDS = ObjectHashSet.from( "_uid", "_id", "_type", "_parent", "_routing", "_index", @@ -110,11 +110,6 @@ public enum MergeReason { private final IndexAnalyzers indexAnalyzers; - /** - * Will create types automatically if they do not exists in the mapping definition yet - */ - private final boolean dynamic; - private volatile String defaultMappingSource; private volatile Map mappers = emptyMap(); @@ -148,24 +143,15 @@ public MapperService(IndexSettings indexSettings, IndexAnalyzers indexAnalyzers, this.searchQuoteAnalyzer = new MapperAnalyzerWrapper(indexAnalyzers.getDefaultSearchQuoteAnalyzer(), p -> p.searchQuoteAnalyzer()); this.mapperRegistry = mapperRegistry; - if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1)) { - if (INDEX_MAPPER_DYNAMIC_SETTING.exists(indexSettings.getSettings())) { - if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_7_0_0_alpha1)) { - throw new IllegalArgumentException("Setting " + INDEX_MAPPER_DYNAMIC_SETTING.getKey() + " was removed after version 6.0.0"); - } else { - DEPRECATION_LOGGER.deprecated("Setting " + INDEX_MAPPER_DYNAMIC_SETTING.getKey() + " is deprecated since indices may not have more than one type anymore."); - } - } - this.dynamic = INDEX_MAPPER_DYNAMIC_DEFAULT; - } else { - this.dynamic = this.indexSettings.getValue(INDEX_MAPPER_DYNAMIC_SETTING); + if (INDEX_MAPPER_DYNAMIC_SETTING.exists(indexSettings.getSettings()) && + indexSettings.getIndexVersionCreated().onOrAfter(Version.V_7_0_0_alpha1)) { + throw new IllegalArgumentException("Setting " + INDEX_MAPPER_DYNAMIC_SETTING.getKey() + " was removed after version 6.0.0"); } + defaultMappingSource = "{\"_default_\":{}}"; if (logger.isTraceEnabled()) { - logger.trace("using dynamic[{}], default mapping source[{}]", dynamic, defaultMappingSource); - } else if (logger.isDebugEnabled()) { - logger.debug("using dynamic[{}]", dynamic); + logger.trace("default mapping source[{}]", defaultMappingSource); } } @@ -739,10 +725,6 @@ public DocumentMapperForType documentMapperWithAutoCreate(String type) { if (mapper != null) { return new DocumentMapperForType(mapper, null); } - if (!dynamic) { - throw new TypeMissingException(index(), - new IllegalStateException("trying to auto create mapping, but dynamic mapping is disabled"), type); - } mapper = parse(type, null, true); return new DocumentMapperForType(mapper, mapper.mapping()); } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingVersionTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingVersionTests.java index 94af6c5454493..293235140d6a6 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingVersionTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingVersionTests.java @@ -19,12 +19,9 @@ package org.elasticsearch.index.mapper; -import org.elasticsearch.Version; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.indices.TypeMissingException; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.InternalSettingsPlugin; @@ -67,14 +64,4 @@ public void testDynamicMappingSettingRemoval() { assertEquals(e.getMessage(), "Setting index.mapper.dynamic was removed after version 6.0.0"); } - public void testDynamicMappingDisablePreEs6() { - Settings settingsPreEs6 = Settings.builder() - .put(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey(), false) - .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_0_0) - .build(); - MapperService preEs6MapperService = createIndex("pre-es6-index", settingsPreEs6).mapperService(); - Exception e = expectThrows(TypeMissingException.class, - () -> preEs6MapperService.documentMapperWithAutoCreate("pre-es6-type")); - assertEquals(e.getMessage(), "type[pre-es6-type] missing"); - } } From 051d0b8c912647cba95a60e9b425d3b6ea7945af Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 13 Sep 2017 10:12:17 +0200 Subject: [PATCH 2/2] iter --- .../org/elasticsearch/index/mapper/MapperService.java | 1 + .../action/support/AutoCreateIndexTests.java | 10 ---------- .../index/mapper/DynamicMappingVersionTests.java | 2 ++ 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 04ee7e53ef1b9..9d46afac3cb23 100755 --- a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -97,6 +97,7 @@ public enum MergeReason { public static final Setting INDEX_MAPPING_DEPTH_LIMIT_SETTING = Setting.longSetting("index.mapping.depth.limit", 20L, 1, Property.Dynamic, Property.IndexScope); public static final boolean INDEX_MAPPER_DYNAMIC_DEFAULT = true; + @Deprecated public static final Setting INDEX_MAPPER_DYNAMIC_SETTING = Setting.boolSetting("index.mapper.dynamic", INDEX_MAPPER_DYNAMIC_DEFAULT, Property.Dynamic, Property.IndexScope, Property.Deprecated); diff --git a/core/src/test/java/org/elasticsearch/action/support/AutoCreateIndexTests.java b/core/src/test/java/org/elasticsearch/action/support/AutoCreateIndexTests.java index 159be84de0791..a0c3a8d1f4e60 100644 --- a/core/src/test/java/org/elasticsearch/action/support/AutoCreateIndexTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/AutoCreateIndexTests.java @@ -108,16 +108,6 @@ public void testExistingIndex() { buildClusterState("index1", "index2", "index3")), equalTo(false)); } - public void testDynamicMappingDisabled() { - Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), randomFrom(true, - randomAlphaOfLengthBetween(1, 10))) - .put(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey(), false).build(); - AutoCreateIndex autoCreateIndex = newAutoCreateIndex(settings); - IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> - autoCreateIndex.shouldAutoCreate(randomAlphaOfLengthBetween(1, 10), buildClusterState())); - assertEquals("no such index and [index.mapper.dynamic] is [false]", e.getMessage()); - } - public void testAutoCreationPatternEnabled() { Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), randomFrom("+index*", "index*")) .build(); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingVersionTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingVersionTests.java index 293235140d6a6..37c887401f24a 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingVersionTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingVersionTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.mapper; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; @@ -62,6 +63,7 @@ public void testDynamicMappingSettingRemoval() { .build(); Exception e = expectThrows(IllegalArgumentException.class, () -> createIndex("test-index", settings)); assertEquals(e.getMessage(), "Setting index.mapper.dynamic was removed after version 6.0.0"); + assertSettingDeprecationsAndWarnings(new Setting[] { MapperService.INDEX_MAPPER_DYNAMIC_SETTING }); } }