diff options
Diffstat (limited to 'core/src/main/java/org')
4 files changed, 30 insertions, 19 deletions
diff --git a/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java b/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java index 890a43107c..1b57a2919f 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java @@ -138,7 +138,6 @@ public final class IndexScopedSettings extends AbstractScopedSettings { MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING, MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING, MapperService.INDEX_MAPPING_DEPTH_LIMIT_SETTING, - MapperService.INDEX_MAPPING_SINGLE_TYPE_SETTING, BitsetFilterCache.INDEX_LOAD_RANDOM_ACCESS_FILTERS_EAGERLY_SETTING, IndexModule.INDEX_STORE_TYPE_SETTING, IndexModule.INDEX_STORE_PRE_LOAD_SETTING, @@ -197,6 +196,9 @@ public final class IndexScopedSettings extends AbstractScopedSettings { case MergePolicyConfig.INDEX_MERGE_ENABLED: case IndexMetaData.INDEX_SHRINK_SOURCE_UUID_KEY: case IndexMetaData.INDEX_SHRINK_SOURCE_NAME_KEY: + case IndexSettings.INDEX_MAPPING_SINGLE_TYPE_SETTING_KEY: + // this was settable in 5.x but not anymore in 6.x so we have to preserve the value ie. make it read-only + // this can be removed in later versions return true; default: return IndexMetaData.INDEX_ROUTING_INITIAL_RECOVERY_GROUP_SETTING.getRawKey().match(key); diff --git a/core/src/main/java/org/elasticsearch/index/IndexSettings.java b/core/src/main/java/org/elasticsearch/index/IndexSettings.java index 537344ca65..fc2e476afc 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/core/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -169,6 +169,20 @@ public final class IndexSettings { public static final Setting<Integer> MAX_SLICES_PER_SCROLL = Setting.intSetting("index.max_slices_per_scroll", 1024, 1, Property.Dynamic, Property.IndexScope); + public static final String INDEX_MAPPING_SINGLE_TYPE_SETTING_KEY = "index.mapping.single_type"; + private static final Setting<Boolean> INDEX_MAPPING_SINGLE_TYPE_SETTING; // private - should not be registered + static { + Function<Settings, String> defValue = settings -> { + boolean singleType = true; + if (settings.getAsVersion(IndexMetaData.SETTING_VERSION_CREATED, null) != null) { + singleType = Version.indexCreated(settings).onOrAfter(Version.V_6_0_0_alpha1); + } + return Boolean.valueOf(singleType).toString(); + }; + INDEX_MAPPING_SINGLE_TYPE_SETTING = Setting.boolSetting(INDEX_MAPPING_SINGLE_TYPE_SETTING_KEY, defValue, Property.IndexScope, + Property.Final); + } + private final Index index; private final Version version; private final Logger logger; @@ -300,7 +314,11 @@ public final class IndexSettings { maxSlicesPerScroll = scopedSettings.get(MAX_SLICES_PER_SCROLL); this.mergePolicyConfig = new MergePolicyConfig(logger, this); this.indexSortConfig = new IndexSortConfig(this); - singleType = scopedSettings.get(MapperService.INDEX_MAPPING_SINGLE_TYPE_SETTING); + singleType = INDEX_MAPPING_SINGLE_TYPE_SETTING.get(indexMetaData.getSettings()); // get this from metadata - it's not registered + if ((singleType || version.before(Version.V_6_0_0_alpha1)) == false) { + throw new AssertionError(index.toString() + "multiple types are only allowed on pre 6.x indices but version is: [" + + version + "]"); + } scopedSettings.addSettingsUpdateConsumer(MergePolicyConfig.INDEX_COMPOUND_FORMAT_SETTING, mergePolicyConfig::setNoCFSRatio); scopedSettings.addSettingsUpdateConsumer(MergePolicyConfig.INDEX_MERGE_POLICY_EXPUNGE_DELETES_ALLOWED_SETTING, mergePolicyConfig::setExpungeDeletesAllowed); 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 50f424c268..e279e12c40 100755 --- a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -97,17 +97,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { public static final boolean INDEX_MAPPER_DYNAMIC_DEFAULT = true; public static final Setting<Boolean> INDEX_MAPPER_DYNAMIC_SETTING = Setting.boolSetting("index.mapper.dynamic", INDEX_MAPPER_DYNAMIC_DEFAULT, Property.Dynamic, Property.IndexScope); - public static final Setting<Boolean> INDEX_MAPPING_SINGLE_TYPE_SETTING; - static { - Function<Settings, String> defValue = settings -> { - boolean singleType = true; - if (settings.getAsVersion(IndexMetaData.SETTING_VERSION_CREATED, null) != null) { - singleType = Version.indexCreated(settings).onOrAfter(Version.V_6_0_0_alpha1); - } - return Boolean.valueOf(singleType).toString(); - }; - INDEX_MAPPING_SINGLE_TYPE_SETTING = Setting.boolSetting("index.mapping.single_type", defValue, Property.IndexScope, Property.Final); - } + private static ObjectHashSet<String> META_FIELDS = ObjectHashSet.from( "_uid", "_id", "_type", "_all", "_parent", "_routing", "_index", "_size", "_timestamp", "_ttl" diff --git a/core/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java index 2092e2521d..72c94edfd0 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java @@ -40,6 +40,7 @@ import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData; import org.elasticsearch.index.fielddata.plain.ConstantIndexFieldData; @@ -85,7 +86,7 @@ public class TypeFieldMapper extends MetadataFieldMapper { @Override public MetadataFieldMapper getDefault(MappedFieldType fieldType, ParserContext context) { - final Settings indexSettings = context.mapperService().getIndexSettings().getSettings(); + final IndexSettings indexSettings = context.mapperService().getIndexSettings(); return new TypeFieldMapper(indexSettings, fieldType); } } @@ -263,18 +264,18 @@ public class TypeFieldMapper extends MetadataFieldMapper { } } - private TypeFieldMapper(Settings indexSettings, MappedFieldType existing) { + private TypeFieldMapper(IndexSettings indexSettings, MappedFieldType existing) { this(existing == null ? defaultFieldType(indexSettings) : existing.clone(), indexSettings); } - private TypeFieldMapper(MappedFieldType fieldType, Settings indexSettings) { - super(NAME, fieldType, defaultFieldType(indexSettings), indexSettings); + private TypeFieldMapper(MappedFieldType fieldType, IndexSettings indexSettings) { + super(NAME, fieldType, defaultFieldType(indexSettings), indexSettings.getSettings()); } - private static MappedFieldType defaultFieldType(Settings indexSettings) { + private static MappedFieldType defaultFieldType(IndexSettings indexSettings) { MappedFieldType defaultFieldType = Defaults.FIELD_TYPE.clone(); - if (MapperService.INDEX_MAPPING_SINGLE_TYPE_SETTING.get(indexSettings)) { + if (indexSettings.isSingleType()) { defaultFieldType.setIndexOptions(IndexOptions.NONE); defaultFieldType.setHasDocValues(false); } else { |