diff --git a/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java index f74d58093a7f5..a0e06bafb4050 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java @@ -182,11 +182,8 @@ private FieldValues scriptValues() { } } - private static final IndexVersion MINIMUM_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099); - - public static final TypeParser PARSER = new TypeParser( - (n, c) -> new Builder(n, c.scriptCompiler(), IGNORE_MALFORMED_SETTING.get(c.getSettings()), c.indexVersionCreated()), - MINIMUM_COMPATIBILITY_VERSION + public static final TypeParser PARSER = createTypeParserWithLegacySupport( + (n, c) -> new Builder(n, c.scriptCompiler(), IGNORE_MALFORMED_SETTING.get(c.getSettings()), c.indexVersionCreated()) ); public static final class BooleanFieldType extends TermBasedFieldType { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java index 39744cbd39f7c..fb17f1c7ebaf8 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java @@ -398,9 +398,7 @@ public DateFieldMapper build(MapperBuilderContext context) { } } - private static final IndexVersion MINIMUM_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099); - - public static final TypeParser MILLIS_PARSER = new TypeParser((n, c) -> { + public static final TypeParser MILLIS_PARSER = createTypeParserWithLegacySupport((n, c) -> { boolean ignoreMalformedByDefault = IGNORE_MALFORMED_SETTING.get(c.getSettings()); return new Builder( n, @@ -410,9 +408,9 @@ public DateFieldMapper build(MapperBuilderContext context) { ignoreMalformedByDefault, c.indexVersionCreated() ); - }, MINIMUM_COMPATIBILITY_VERSION); + }); - public static final TypeParser NANOS_PARSER = new TypeParser((n, c) -> { + public static final TypeParser NANOS_PARSER = createTypeParserWithLegacySupport((n, c) -> { boolean ignoreMalformedByDefault = IGNORE_MALFORMED_SETTING.get(c.getSettings()); return new Builder( n, @@ -422,7 +420,7 @@ public DateFieldMapper build(MapperBuilderContext context) { ignoreMalformedByDefault, c.indexVersionCreated() ); - }, MINIMUM_COMPATIBILITY_VERSION); + }); public static final class DateFieldType extends MappedFieldType { final DateFormatter dateTimeFormatter; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java index 7238127571fed..ffd60efc772f9 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java @@ -1618,6 +1618,12 @@ public static BiConsumer notFromDynamicTemplates(S }; } + private static final IndexVersion MINIMUM_LEGACY_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099); + + public static TypeParser createTypeParserWithLegacySupport(BiFunction builderFunction) { + return new TypeParser(builderFunction, MINIMUM_LEGACY_COMPATIBILITY_VERSION); + } + /** * TypeParser implementation that automatically handles parsing */ @@ -1632,14 +1638,14 @@ public static final class TypeParser implements Mapper.TypeParser { * @param builderFunction a function that produces a Builder from a name and parsercontext */ public TypeParser(BiFunction builderFunction) { - this(builderFunction, (n, c) -> {}, IndexVersions.MINIMUM_COMPATIBLE); + this(builderFunction, (n, c) -> {}, IndexVersions.MINIMUM_READONLY_COMPATIBLE); } /** - * Variant of {@link #TypeParser(BiFunction)} that allows to defining a minimumCompatibilityVersion to + * Variant of {@link #TypeParser(BiFunction)} that allows to define a minimumCompatibilityVersion to * allow parsing mapping definitions of legacy indices (see {@link Mapper.TypeParser#supportsVersion(IndexVersion)}). */ - public TypeParser(BiFunction builderFunction, IndexVersion minimumCompatibilityVersion) { + private TypeParser(BiFunction builderFunction, IndexVersion minimumCompatibilityVersion) { this(builderFunction, (n, c) -> {}, minimumCompatibilityVersion); } @@ -1647,14 +1653,14 @@ public TypeParser( BiFunction builderFunction, BiConsumer contextValidator ) { - this(builderFunction, contextValidator, IndexVersions.MINIMUM_COMPATIBLE); + this(builderFunction, contextValidator, IndexVersions.MINIMUM_READONLY_COMPATIBLE); } public TypeParser( BiFunction builderFunction, List> contextValidator ) { - this(builderFunction, (n, c) -> contextValidator.forEach(v -> v.accept(n, c)), IndexVersions.MINIMUM_COMPATIBLE); + this(builderFunction, (n, c) -> contextValidator.forEach(v -> v.accept(n, c)), IndexVersions.MINIMUM_READONLY_COMPATIBLE); } private TypeParser( diff --git a/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java index 161e1ba84aa40..0824e5381ff65 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java @@ -228,17 +228,14 @@ public FieldMapper build(MapperBuilderContext context) { } - private static final IndexVersion MINIMUM_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099); - - public static TypeParser PARSER = new TypeParser( + public static TypeParser PARSER = createTypeParserWithLegacySupport( (n, c) -> new Builder( n, c.scriptCompiler(), IGNORE_MALFORMED_SETTING.get(c.getSettings()), c.indexVersionCreated(), c.getIndexSettings().getMode() - ), - MINIMUM_COMPATIBILITY_VERSION + ) ); private final Builder builder; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java index 2f64955b48627..0204a2b10013a 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java @@ -204,12 +204,10 @@ public IpFieldMapper build(MapperBuilderContext context) { } - private static final IndexVersion MINIMUM_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099); - - public static final TypeParser PARSER = new TypeParser((n, c) -> { + public static final TypeParser PARSER = createTypeParserWithLegacySupport((n, c) -> { boolean ignoreMalformedByDefault = IGNORE_MALFORMED_SETTING.get(c.getSettings()); return new Builder(n, c.scriptCompiler(), ignoreMalformedByDefault, c.indexVersionCreated()); - }, MINIMUM_COMPATIBILITY_VERSION); + }); public static final class IpFieldType extends SimpleMappedFieldType { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java index 32aa422b18bcc..e970789225059 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java @@ -385,9 +385,7 @@ public KeywordFieldMapper build(MapperBuilderContext context) { } } - private static final IndexVersion MINIMUM_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099); - - public static final TypeParser PARSER = new TypeParser(Builder::new, MINIMUM_COMPATIBILITY_VERSION); + public static final TypeParser PARSER = createTypeParserWithLegacySupport(Builder::new); public static final class KeywordFieldType extends StringFieldType { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/Mapper.java b/server/src/main/java/org/elasticsearch/index/mapper/Mapper.java index 6bc63bdbcceaf..5cbdffc28ba74 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/Mapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/Mapper.java @@ -131,7 +131,7 @@ public interface TypeParser { * Whether we can parse this type on indices with the given index created version. */ default boolean supportsVersion(IndexVersion indexCreatedVersion) { - return indexCreatedVersion.onOrAfter(IndexVersions.MINIMUM_COMPATIBLE); + return indexCreatedVersion.onOrAfter(IndexVersions.MINIMUM_READONLY_COMPATIBLE); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MapperRegistry.java b/server/src/main/java/org/elasticsearch/index/mapper/MapperRegistry.java index ea94576f5c536..44f7def74ec0e 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/MapperRegistry.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MapperRegistry.java @@ -57,9 +57,13 @@ public MapperRegistry( */ public Mapper.TypeParser getMapperParser(String type, IndexVersion indexVersionCreated) { Mapper.TypeParser parser = mapperParsers.get(type); - if (indexVersionCreated.isLegacyIndexVersion() && (parser == null || parser.supportsVersion(indexVersionCreated) == false)) { - return PlaceHolderFieldMapper.PARSER.apply(type); + if (indexVersionCreated.isLegacyIndexVersion()) { + if (parser == null || parser.supportsVersion(indexVersionCreated) == false) { + return PlaceHolderFieldMapper.PARSER.apply(type); + } + return parser; } else { + assert parser == null || parser.supportsVersion(indexVersionCreated); return parser; } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java index 8c21dfea31b9a..1b8fb3dfc101c 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java @@ -89,8 +89,6 @@ private static NumberFieldMapper toType(FieldMapper in) { return (NumberFieldMapper) in; } - private static final IndexVersion MINIMUM_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099); - public static final class Builder extends FieldMapper.DimensionBuilder { private final Parameter indexed; @@ -1378,16 +1376,8 @@ private boolean isOutOfRange(Object value) { NumberType(String name, NumericType numericType) { this.name = name; this.numericType = numericType; - this.parser = new TypeParser( - (n, c) -> new Builder( - n, - this, - c.scriptCompiler(), - c.getSettings(), - c.indexVersionCreated(), - c.getIndexSettings().getMode() - ), - MINIMUM_COMPATIBILITY_VERSION + this.parser = createTypeParserWithLegacySupport( + (n, c) -> new Builder(n, this, c.scriptCompiler(), c.getSettings(), c.indexVersionCreated(), c.getIndexSettings().getMode()) ); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java index cf75f1ddf3b94..b7323f2c0e3e4 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java @@ -480,11 +480,8 @@ public TextFieldMapper build(MapperBuilderContext context) { } } - private static final IndexVersion MINIMUM_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099); - - public static final TypeParser PARSER = new TypeParser( - (n, c) -> new Builder(n, c.indexVersionCreated(), c.getIndexAnalyzers(), SourceFieldMapper.isSynthetic(c.getIndexSettings())), - MINIMUM_COMPATIBILITY_VERSION + public static final TypeParser PARSER = createTypeParserWithLegacySupport( + (n, c) -> new Builder(n, c.indexVersionCreated(), c.getIndexAnalyzers(), SourceFieldMapper.isSynthetic(c.getIndexSettings())) ); private static class PhraseWrappedAnalyzer extends AnalyzerWrapper {