From a5815956acfd358b5750f22f28310a185e1039ab Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Tue, 24 Nov 2020 08:25:22 -0800 Subject: [PATCH] Remove unnecessary references to index version. (#65402) * Remove unnecessary references in mapping code. * Remove version from QueryAnalyzer#analyze. --- .../index/mapper/CompletionFieldMapper.java | 4 ++-- .../elasticsearch/index/mapper/DocumentMapper.java | 1 - .../index/mapper/DocumentMapperParser.java | 12 +++++------- .../java/org/elasticsearch/index/mapper/Mapping.java | 10 +++------- .../org/elasticsearch/index/mapper/ObjectMapper.java | 5 ++--- .../elasticsearch/index/mapper/RuntimeFieldType.java | 2 +- .../elasticsearch/index/mapper/TextFieldMapper.java | 4 ++-- .../org/elasticsearch/index/mapper/TypeParsers.java | 2 +- .../completion/context/CategoryContextMapping.java | 3 +-- .../suggest/completion/context/ContextMappings.java | 11 +++++------ .../action/bulk/TransportShardBulkActionTests.java | 6 +++--- .../action/index/MappingUpdatedActionTests.java | 4 ++-- .../index/engine/InternalEngineTests.java | 2 +- 13 files changed, 28 insertions(+), 38 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java index 5b4a45be141a4..c5874ff563e21 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java @@ -68,7 +68,7 @@ *
  • "min_input_length": 50 (default)
  • *
  • "contexts" : CONTEXTS
  • * - * see {@link ContextMappings#load(Object, Version)} for CONTEXTS
    + * see {@link ContextMappings#load(Object)} for CONTEXTS
    * see {@link #parse(ParseContext)} for acceptable inputs for indexing
    *

    * This field type constructs completion queries that are run @@ -129,7 +129,7 @@ public static class Builder extends FieldMapper.Builder { m -> builder(m).preservePosInc.get(), Defaults.DEFAULT_POSITION_INCREMENTS) .alwaysSerialize(); private final Parameter contexts = new Parameter<>("contexts", false, () -> null, - (n, c, o) -> ContextMappings.load(o, c.indexVersionCreated()), m -> builder(m).contexts.get()) + (n, c, o) -> ContextMappings.load(o), m -> builder(m).contexts.get()) .setSerializer((b, n, c) -> { if (c == null) { return; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java index 6af44b725355c..5ec54d14c1450 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java @@ -88,7 +88,6 @@ public Builder put(MetadataFieldMapper.Builder mapper) { public DocumentMapper build() { Objects.requireNonNull(rootObjectMapper, "Mapper builder must have the root object mapper set"); Mapping mapping = new Mapping( - indexSettings.getIndexVersionCreated(), rootObjectMapper, metadataMappers.values().toArray(new MetadataFieldMapper[0]), meta); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java b/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java index 8d58c780cbf4d..938733ee4025e 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.mapper; -import org.elasticsearch.Version; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.compress.CompressedXContent; @@ -120,7 +119,7 @@ private DocumentMapper parse(String type, Map mapping, String de Map fieldNodeMap = (Map) fieldNode; docBuilder.put(typeParser.parse(fieldName, fieldNodeMap, parserContext)); fieldNodeMap.remove("type"); - checkNoRemainingFields(fieldName, fieldNodeMap, parserContext.indexVersionCreated()); + checkNoRemainingFields(fieldName, fieldNodeMap); } } @@ -131,17 +130,16 @@ private DocumentMapper parse(String type, Map mapping, String de docBuilder.meta(unmodifiableMap(new HashMap<>(meta))); } - checkNoRemainingFields(mapping, parserContext.indexVersionCreated(), "Root mapping definition has unsupported parameters: "); + checkNoRemainingFields(mapping, "Root mapping definition has unsupported parameters: "); return docBuilder.build(); } - public static void checkNoRemainingFields(String fieldName, Map fieldNodeMap, Version indexVersionCreated) { - checkNoRemainingFields(fieldNodeMap, indexVersionCreated, - "Mapping definition for [" + fieldName + "] has unsupported parameters: "); + public static void checkNoRemainingFields(String fieldName, Map fieldNodeMap) { + checkNoRemainingFields(fieldNodeMap, "Mapping definition for [" + fieldName + "] has unsupported parameters: "); } - public static void checkNoRemainingFields(Map fieldNodeMap, Version indexVersionCreated, String message) { + public static void checkNoRemainingFields(Map fieldNodeMap, String message) { if (!fieldNodeMap.isEmpty()) { throw new MapperParsingException(message + getRemainingFields(fieldNodeMap)); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/Mapping.java b/server/src/main/java/org/elasticsearch/index/mapper/Mapping.java index b36d240be0b73..45ff673397c7d 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/Mapping.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/Mapping.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.mapper; -import org.elasticsearch.Version; import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment; @@ -44,16 +43,13 @@ */ public final class Mapping implements ToXContentFragment { - final Version indexCreated; final RootObjectMapper root; final MetadataFieldMapper[] metadataMappers; final Map, MetadataFieldMapper> metadataMappersMap; final Map metadataMappersByName; final Map meta; - public Mapping(Version indexCreated, RootObjectMapper rootObjectMapper, - MetadataFieldMapper[] metadataMappers, Map meta) { - this.indexCreated = indexCreated; + public Mapping(RootObjectMapper rootObjectMapper, MetadataFieldMapper[] metadataMappers, Map meta) { this.metadataMappers = metadataMappers; Map, MetadataFieldMapper> metadataMappersMap = new HashMap<>(); Map metadataMappersByName = new HashMap<>(); @@ -90,7 +86,7 @@ public void validate(MappingLookup mappers) { * Generate a mapping update for the given root object mapper. */ public Mapping mappingUpdate(Mapper rootObjectMapper) { - return new Mapping(indexCreated, (RootObjectMapper) rootObjectMapper, metadataMappers, meta); + return new Mapping((RootObjectMapper) rootObjectMapper, metadataMappers, meta); } /** Get the root mapper with the given class. */ @@ -137,7 +133,7 @@ public Mapping merge(Mapping mergeWith, MergeReason reason) { XContentHelper.mergeDefaults(mergedMeta, meta); } - return new Mapping(indexCreated, mergedRoot, mergedMetadataMappers.values().toArray(new MetadataFieldMapper[0]), mergedMeta); + return new Mapping(mergedRoot, mergedMetadataMappers.values().toArray(new MetadataFieldMapper[0]), mergedMeta); } public MetadataFieldMapper getMetadataMapper(String mapperName) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java index b357e41273a46..5baaee86a717c 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java @@ -321,7 +321,7 @@ protected static void parseProperties(ObjectMapper.Builder objBuilder, Map node, } runtimeFieldTypeConsumer.accept(typeParser.parse(fieldName, propNode, parserContext)); propNode.remove("type"); - DocumentMapperParser.checkNoRemainingFields(fieldName, propNode, parserContext.indexVersionCreated()); + DocumentMapperParser.checkNoRemainingFields(fieldName, propNode); iterator.remove(); } else { throw new MapperParsingException("Expected map for runtime field [" + fieldName + "] definition but got a " 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 1a8a09db7da25..a47295a8b685c 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java @@ -177,7 +177,7 @@ private static PrefixConfig parsePrefixConfig(String propName, ParserContext par Defaults.INDEX_PREFIX_MIN_CHARS); int maxChars = XContentMapValues.nodeIntegerValue(indexPrefix.remove("max_chars"), Defaults.INDEX_PREFIX_MAX_CHARS); - DocumentMapperParser.checkNoRemainingFields(propName, indexPrefix, parserContext.indexVersionCreated()); + DocumentMapperParser.checkNoRemainingFields(propName, indexPrefix); return new PrefixConfig(minChars, maxChars); } @@ -232,7 +232,7 @@ private static FielddataFrequencyFilter parseFrequencyFilter(String name, Parser double minFrequency = XContentMapValues.nodeDoubleValue(frequencyFilter.remove("min"), 0); double maxFrequency = XContentMapValues.nodeDoubleValue(frequencyFilter.remove("max"), Integer.MAX_VALUE); int minSegmentSize = XContentMapValues.nodeIntegerValue(frequencyFilter.remove("min_segment_size"), 0); - DocumentMapperParser.checkNoRemainingFields(name, frequencyFilter, parserContext.indexVersionCreated()); + DocumentMapperParser.checkNoRemainingFields(name, frequencyFilter); return new FielddataFrequencyFilter(minFrequency, maxFrequency, minSegmentSize); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java b/server/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java index 43a97f5e07d29..fbb62ac769d67 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java @@ -148,7 +148,7 @@ public static boolean parseMultiField(Consumer multiFieldsB FieldMapper.TypeParser fieldTypeParser = (FieldMapper.TypeParser) typeParser; multiFieldsBuilder.accept(fieldTypeParser.parse(multiFieldName, multiFieldNodes, parserContext)); multiFieldNodes.remove("type"); - DocumentMapperParser.checkNoRemainingFields(propName, multiFieldNodes, parserContext.indexVersionCreated()); + DocumentMapperParser.checkNoRemainingFields(propName, multiFieldNodes); } return true; } diff --git a/server/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java b/server/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java index feadc41807154..2d3a830d09100 100644 --- a/server/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java +++ b/server/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java @@ -24,7 +24,6 @@ import org.apache.lucene.document.StoredField; import org.apache.lucene.index.IndexableField; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.Version; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser.Token; @@ -78,7 +77,7 @@ public String getFieldName() { /** * Loads a named {@link CategoryContextMapping} instance * from a map. - * see {@link ContextMappings#load(Object, Version)} + * see {@link ContextMappings#load(Object)} * * Acceptable map param: path */ diff --git a/server/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMappings.java b/server/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMappings.java index 7ebb62806ff80..52654738cd697 100644 --- a/server/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMappings.java +++ b/server/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMappings.java @@ -25,7 +25,6 @@ import org.apache.lucene.util.CharsRef; import org.apache.lucene.util.CharsRefBuilder; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.Version; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.mapper.CompletionFieldMapper; @@ -224,26 +223,26 @@ public Map> getNamedContexts(List contexts) { * [{"name": .., "type": .., ..}, {..}] * */ - public static ContextMappings load(Object configuration, Version indexVersionCreated) throws ElasticsearchParseException { + public static ContextMappings load(Object configuration) throws ElasticsearchParseException { final List> contextMappings; if (configuration instanceof List) { contextMappings = new ArrayList<>(); List configurations = (List) configuration; for (Object contextConfig : configurations) { - contextMappings.add(load((Map) contextConfig, indexVersionCreated)); + contextMappings.add(load((Map) contextConfig)); } if (contextMappings.size() == 0) { throw new ElasticsearchParseException("expected at least one context mapping"); } } else if (configuration instanceof Map) { - contextMappings = Collections.singletonList(load(((Map) configuration), indexVersionCreated)); + contextMappings = Collections.singletonList(load(((Map) configuration))); } else { throw new ElasticsearchParseException("expected a list or an entry of context mapping"); } return new ContextMappings(contextMappings); } - private static ContextMapping load(Map contextConfig, Version indexVersionCreated) { + private static ContextMapping load(Map contextConfig) { String name = extractRequiredValue(contextConfig, FIELD_NAME); String type = extractRequiredValue(contextConfig, FIELD_TYPE); final ContextMapping contextMapping; @@ -257,7 +256,7 @@ private static ContextMapping load(Map contextConfig, Version default: throw new ElasticsearchParseException("unknown context type[" + type + "]"); } - DocumentMapperParser.checkNoRemainingFields(name, contextConfig, indexVersionCreated); + DocumentMapperParser.checkNoRemainingFields(name, contextConfig); return contextMapping; } diff --git a/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java b/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java index 110ffeffed22d..eaabe1dc042e2 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java @@ -244,7 +244,7 @@ public void testExecuteBulkIndexRequestWithMappingUpdates() throws Exception { new BulkShardRequest(shardId, RefreshPolicy.NONE, items); Engine.IndexResult mappingUpdate = - new Engine.IndexResult(new Mapping(null, mock(RootObjectMapper.class), new MetadataFieldMapper[0], Collections.emptyMap())); + new Engine.IndexResult(new Mapping(mock(RootObjectMapper.class), new MetadataFieldMapper[0], Collections.emptyMap())); Translog.Location resultLocation = new Translog.Location(42, 42, 42); Engine.IndexResult success = new FakeIndexResult(1, 1, 13, true, resultLocation); @@ -779,7 +779,7 @@ public void testRetries() throws Exception { "I'm conflicted <(;_;)>"); Engine.IndexResult conflictedResult = new Engine.IndexResult(err, 0); Engine.IndexResult mappingUpdate = - new Engine.IndexResult(new Mapping(null, mock(RootObjectMapper.class), new MetadataFieldMapper[0], Collections.emptyMap())); + new Engine.IndexResult(new Mapping(mock(RootObjectMapper.class), new MetadataFieldMapper[0], Collections.emptyMap())); Translog.Location resultLocation = new Translog.Location(42, 42, 42); Engine.IndexResult success = new FakeIndexResult(1, 1, 13, true, resultLocation); @@ -858,7 +858,7 @@ public void testForceExecutionOnRejectionAfterMappingUpdate() throws Exception { BulkShardRequest bulkShardRequest = new BulkShardRequest(shardId, RefreshPolicy.NONE, items); Engine.IndexResult mappingUpdate = - new Engine.IndexResult(new Mapping(null, mock(RootObjectMapper.class), new MetadataFieldMapper[0], Collections.emptyMap())); + new Engine.IndexResult(new Mapping(mock(RootObjectMapper.class), new MetadataFieldMapper[0], Collections.emptyMap())); Translog.Location resultLocation1 = new Translog.Location(42, 36, 36); Translog.Location resultLocation2 = new Translog.Location(42, 42, 42); Engine.IndexResult success1 = new FakeIndexResult(1, 1, 10, true, resultLocation1); diff --git a/server/src/test/java/org/elasticsearch/cluster/action/index/MappingUpdatedActionTests.java b/server/src/test/java/org/elasticsearch/cluster/action/index/MappingUpdatedActionTests.java index 5851b8de9502a..d2a59817ab009 100644 --- a/server/src/test/java/org/elasticsearch/cluster/action/index/MappingUpdatedActionTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/action/index/MappingUpdatedActionTests.java @@ -155,7 +155,7 @@ public void testSendUpdateMappingUsingPutMappingAction() { mua.setClient(client); RootObjectMapper rootObjectMapper = new RootObjectMapper.Builder("name", Version.CURRENT).build(new ContentPath()); - Mapping update = new Mapping(Version.V_7_8_0, rootObjectMapper, new MetadataFieldMapper[0], Map.of()); + Mapping update = new Mapping(rootObjectMapper, new MetadataFieldMapper[0], Map.of()); mua.sendUpdateMapping(new Index("name", "uuid"), "type", update, ActionListener.wrap(() -> {})); verify(indicesAdminClient).putMapping(any(), any()); @@ -180,7 +180,7 @@ public void testSendUpdateMappingUsingAutoPutMappingAction() { mua.setClient(client); RootObjectMapper rootObjectMapper = new RootObjectMapper.Builder("name", Version.CURRENT).build(new ContentPath()); - Mapping update = new Mapping(Version.V_7_9_0, rootObjectMapper, new MetadataFieldMapper[0], Map.of()); + Mapping update = new Mapping(rootObjectMapper, new MetadataFieldMapper[0], Map.of()); mua.sendUpdateMapping(new Index("name", "uuid"), "type", update, ActionListener.wrap(() -> {})); verify(indicesAdminClient).execute(eq(AutoPutMappingAction.INSTANCE), any(), any()); diff --git a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index b81c4f3e11b2c..0e0c371db2c71 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -3116,7 +3116,7 @@ public void testSkipTranslogReplay() throws IOException { private Mapping dynamicUpdate() { final RootObjectMapper root = new RootObjectMapper.Builder("some_type", Version.CURRENT).build(new ContentPath()); - return new Mapping(Version.CURRENT, root, new MetadataFieldMapper[0], emptyMap()); + return new Mapping(root, new MetadataFieldMapper[0], emptyMap()); } private Path[] filterExtraFSFiles(Path[] files) {