Skip to content

Commit

Permalink
Remove MapperService#dynamic. (#26603)
Browse files Browse the repository at this point in the history
We ignore it as of 6.0 and forbid it as of 7.0.
  • Loading branch information
jpountz authored Sep 13, 2017
1 parent c709b8d commit 64770b3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,8 +97,10 @@ public enum MergeReason {
public static final Setting<Long> 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<Boolean> 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<String> META_FIELDS = ObjectHashSet.from(
"_uid", "_id", "_type", "_parent", "_routing", "_index",
Expand All @@ -110,11 +111,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<String, DocumentMapper> mappers = emptyMap();
Expand Down Expand Up @@ -148,24 +144,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);
}
}

Expand Down Expand Up @@ -739,10 +726,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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@

package org.elasticsearch.index.mapper;

import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Setting;
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;
Expand Down Expand Up @@ -65,16 +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 });
}

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");
}
}

0 comments on commit 64770b3

Please sign in to comment.