Skip to content

Commit 49ebd42

Browse files
authored
Lower default mappings parsing compatibility to MINIMUM_READONLY_COMPATIBLE (#119017)
Legacy indices check what minimum compatibility version the type parser supports, for every field type found in the mappings. Only some of the basic fields are supported, otherwise a placeholder mapper is created in place of the real field. The minimum supported version is v5 for the supported field mappers. For all the others, we can lower that from MINIMUM_COMPATIBLE to MINIMUM_READONLY_COMPATIBLE. This commit also centralizes the creation of type parsers that declare support for archive indices, as they all declare the same version.
1 parent 21bcc31 commit 49ebd42

File tree

10 files changed

+33
-48
lines changed

10 files changed

+33
-48
lines changed

server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,8 @@ private FieldValues<Boolean> scriptValues() {
182182
}
183183
}
184184

185-
private static final IndexVersion MINIMUM_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099);
186-
187-
public static final TypeParser PARSER = new TypeParser(
188-
(n, c) -> new Builder(n, c.scriptCompiler(), IGNORE_MALFORMED_SETTING.get(c.getSettings()), c.indexVersionCreated()),
189-
MINIMUM_COMPATIBILITY_VERSION
185+
public static final TypeParser PARSER = createTypeParserWithLegacySupport(
186+
(n, c) -> new Builder(n, c.scriptCompiler(), IGNORE_MALFORMED_SETTING.get(c.getSettings()), c.indexVersionCreated())
190187
);
191188

192189
public static final class BooleanFieldType extends TermBasedFieldType {

server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,7 @@ public DateFieldMapper build(MapperBuilderContext context) {
398398
}
399399
}
400400

401-
private static final IndexVersion MINIMUM_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099);
402-
403-
public static final TypeParser MILLIS_PARSER = new TypeParser((n, c) -> {
401+
public static final TypeParser MILLIS_PARSER = createTypeParserWithLegacySupport((n, c) -> {
404402
boolean ignoreMalformedByDefault = IGNORE_MALFORMED_SETTING.get(c.getSettings());
405403
return new Builder(
406404
n,
@@ -410,9 +408,9 @@ public DateFieldMapper build(MapperBuilderContext context) {
410408
ignoreMalformedByDefault,
411409
c.indexVersionCreated()
412410
);
413-
}, MINIMUM_COMPATIBILITY_VERSION);
411+
});
414412

415-
public static final TypeParser NANOS_PARSER = new TypeParser((n, c) -> {
413+
public static final TypeParser NANOS_PARSER = createTypeParserWithLegacySupport((n, c) -> {
416414
boolean ignoreMalformedByDefault = IGNORE_MALFORMED_SETTING.get(c.getSettings());
417415
return new Builder(
418416
n,
@@ -422,7 +420,7 @@ public DateFieldMapper build(MapperBuilderContext context) {
422420
ignoreMalformedByDefault,
423421
c.indexVersionCreated()
424422
);
425-
}, MINIMUM_COMPATIBILITY_VERSION);
423+
});
426424

427425
public static final class DateFieldType extends MappedFieldType {
428426
final DateFormatter dateTimeFormatter;

server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,12 @@ public static BiConsumer<String, MappingParserContext> notFromDynamicTemplates(S
16181618
};
16191619
}
16201620

1621+
private static final IndexVersion MINIMUM_LEGACY_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099);
1622+
1623+
public static TypeParser createTypeParserWithLegacySupport(BiFunction<String, MappingParserContext, Builder> builderFunction) {
1624+
return new TypeParser(builderFunction, MINIMUM_LEGACY_COMPATIBILITY_VERSION);
1625+
}
1626+
16211627
/**
16221628
* TypeParser implementation that automatically handles parsing
16231629
*/
@@ -1632,29 +1638,29 @@ public static final class TypeParser implements Mapper.TypeParser {
16321638
* @param builderFunction a function that produces a Builder from a name and parsercontext
16331639
*/
16341640
public TypeParser(BiFunction<String, MappingParserContext, Builder> builderFunction) {
1635-
this(builderFunction, (n, c) -> {}, IndexVersions.MINIMUM_COMPATIBLE);
1641+
this(builderFunction, (n, c) -> {}, IndexVersions.MINIMUM_READONLY_COMPATIBLE);
16361642
}
16371643

16381644
/**
1639-
* Variant of {@link #TypeParser(BiFunction)} that allows to defining a minimumCompatibilityVersion to
1645+
* Variant of {@link #TypeParser(BiFunction)} that allows to define a minimumCompatibilityVersion to
16401646
* allow parsing mapping definitions of legacy indices (see {@link Mapper.TypeParser#supportsVersion(IndexVersion)}).
16411647
*/
1642-
public TypeParser(BiFunction<String, MappingParserContext, Builder> builderFunction, IndexVersion minimumCompatibilityVersion) {
1648+
private TypeParser(BiFunction<String, MappingParserContext, Builder> builderFunction, IndexVersion minimumCompatibilityVersion) {
16431649
this(builderFunction, (n, c) -> {}, minimumCompatibilityVersion);
16441650
}
16451651

16461652
public TypeParser(
16471653
BiFunction<String, MappingParserContext, Builder> builderFunction,
16481654
BiConsumer<String, MappingParserContext> contextValidator
16491655
) {
1650-
this(builderFunction, contextValidator, IndexVersions.MINIMUM_COMPATIBLE);
1656+
this(builderFunction, contextValidator, IndexVersions.MINIMUM_READONLY_COMPATIBLE);
16511657
}
16521658

16531659
public TypeParser(
16541660
BiFunction<String, MappingParserContext, Builder> builderFunction,
16551661
List<BiConsumer<String, MappingParserContext>> contextValidator
16561662
) {
1657-
this(builderFunction, (n, c) -> contextValidator.forEach(v -> v.accept(n, c)), IndexVersions.MINIMUM_COMPATIBLE);
1663+
this(builderFunction, (n, c) -> contextValidator.forEach(v -> v.accept(n, c)), IndexVersions.MINIMUM_READONLY_COMPATIBLE);
16581664
}
16591665

16601666
private TypeParser(

server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,14 @@ public FieldMapper build(MapperBuilderContext context) {
228228

229229
}
230230

231-
private static final IndexVersion MINIMUM_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099);
232-
233-
public static TypeParser PARSER = new TypeParser(
231+
public static TypeParser PARSER = createTypeParserWithLegacySupport(
234232
(n, c) -> new Builder(
235233
n,
236234
c.scriptCompiler(),
237235
IGNORE_MALFORMED_SETTING.get(c.getSettings()),
238236
c.indexVersionCreated(),
239237
c.getIndexSettings().getMode()
240-
),
241-
MINIMUM_COMPATIBILITY_VERSION
238+
)
242239
);
243240

244241
private final Builder builder;

server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,10 @@ public IpFieldMapper build(MapperBuilderContext context) {
204204

205205
}
206206

207-
private static final IndexVersion MINIMUM_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099);
208-
209-
public static final TypeParser PARSER = new TypeParser((n, c) -> {
207+
public static final TypeParser PARSER = createTypeParserWithLegacySupport((n, c) -> {
210208
boolean ignoreMalformedByDefault = IGNORE_MALFORMED_SETTING.get(c.getSettings());
211209
return new Builder(n, c.scriptCompiler(), ignoreMalformedByDefault, c.indexVersionCreated());
212-
}, MINIMUM_COMPATIBILITY_VERSION);
210+
});
213211

214212
public static final class IpFieldType extends SimpleMappedFieldType {
215213

server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,7 @@ public KeywordFieldMapper build(MapperBuilderContext context) {
385385
}
386386
}
387387

388-
private static final IndexVersion MINIMUM_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099);
389-
390-
public static final TypeParser PARSER = new TypeParser(Builder::new, MINIMUM_COMPATIBILITY_VERSION);
388+
public static final TypeParser PARSER = createTypeParserWithLegacySupport(Builder::new);
391389

392390
public static final class KeywordFieldType extends StringFieldType {
393391

server/src/main/java/org/elasticsearch/index/mapper/Mapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public interface TypeParser {
131131
* Whether we can parse this type on indices with the given index created version.
132132
*/
133133
default boolean supportsVersion(IndexVersion indexCreatedVersion) {
134-
return indexCreatedVersion.onOrAfter(IndexVersions.MINIMUM_COMPATIBLE);
134+
return indexCreatedVersion.onOrAfter(IndexVersions.MINIMUM_READONLY_COMPATIBLE);
135135
}
136136
}
137137

server/src/main/java/org/elasticsearch/index/mapper/MapperRegistry.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ public MapperRegistry(
5757
*/
5858
public Mapper.TypeParser getMapperParser(String type, IndexVersion indexVersionCreated) {
5959
Mapper.TypeParser parser = mapperParsers.get(type);
60-
if (indexVersionCreated.isLegacyIndexVersion() && (parser == null || parser.supportsVersion(indexVersionCreated) == false)) {
61-
return PlaceHolderFieldMapper.PARSER.apply(type);
60+
if (indexVersionCreated.isLegacyIndexVersion()) {
61+
if (parser == null || parser.supportsVersion(indexVersionCreated) == false) {
62+
return PlaceHolderFieldMapper.PARSER.apply(type);
63+
}
64+
return parser;
6265
} else {
66+
assert parser == null || parser.supportsVersion(indexVersionCreated);
6367
return parser;
6468
}
6569
}

server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ private static NumberFieldMapper toType(FieldMapper in) {
8989
return (NumberFieldMapper) in;
9090
}
9191

92-
private static final IndexVersion MINIMUM_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099);
93-
9492
public static final class Builder extends FieldMapper.DimensionBuilder {
9593

9694
private final Parameter<Boolean> indexed;
@@ -1378,16 +1376,8 @@ private boolean isOutOfRange(Object value) {
13781376
NumberType(String name, NumericType numericType) {
13791377
this.name = name;
13801378
this.numericType = numericType;
1381-
this.parser = new TypeParser(
1382-
(n, c) -> new Builder(
1383-
n,
1384-
this,
1385-
c.scriptCompiler(),
1386-
c.getSettings(),
1387-
c.indexVersionCreated(),
1388-
c.getIndexSettings().getMode()
1389-
),
1390-
MINIMUM_COMPATIBILITY_VERSION
1379+
this.parser = createTypeParserWithLegacySupport(
1380+
(n, c) -> new Builder(n, this, c.scriptCompiler(), c.getSettings(), c.indexVersionCreated(), c.getIndexSettings().getMode())
13911381
);
13921382
}
13931383

server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,8 @@ public TextFieldMapper build(MapperBuilderContext context) {
480480
}
481481
}
482482

483-
private static final IndexVersion MINIMUM_COMPATIBILITY_VERSION = IndexVersion.fromId(5000099);
484-
485-
public static final TypeParser PARSER = new TypeParser(
486-
(n, c) -> new Builder(n, c.indexVersionCreated(), c.getIndexAnalyzers(), SourceFieldMapper.isSynthetic(c.getIndexSettings())),
487-
MINIMUM_COMPATIBILITY_VERSION
483+
public static final TypeParser PARSER = createTypeParserWithLegacySupport(
484+
(n, c) -> new Builder(n, c.indexVersionCreated(), c.getIndexAnalyzers(), SourceFieldMapper.isSynthetic(c.getIndexSettings()))
488485
);
489486

490487
private static class PhraseWrappedAnalyzer extends AnalyzerWrapper {

0 commit comments

Comments
 (0)