diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yml index 2aade93ee66..629a6d4de34 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yml @@ -44,8 +44,8 @@ setup: "Nested doc version and seqIDs": - skip: - version: "all" #" - 6.99.99" - reason: "AwaitsFix https://github.com/elastic/elasticsearch/issues/57831"#"Triggers warnings before 7.0" + version: " - 6.99.99" + reason: "Triggers warnings before 7.0" - do: index: diff --git a/server/src/main/java/org/elasticsearch/index/get/GetResult.java b/server/src/main/java/org/elasticsearch/index/get/GetResult.java index 063e934d038..77df38b5086 100644 --- a/server/src/main/java/org/elasticsearch/index/get/GetResult.java +++ b/server/src/main/java/org/elasticsearch/index/get/GetResult.java @@ -99,7 +99,7 @@ public class GetResult implements Writeable, Iterable, ToXContent documentFields = new HashMap<>(); metaFields = new HashMap<>(); fields.forEach((fieldName, docField) -> - (MapperService.isMetadataFieldStatic(fieldName) ? metaFields : documentFields).put(fieldName, docField)); + (MapperService.META_FIELDS_BEFORE_7DOT8.contains(fieldName) ? metaFields : documentFields).put(fieldName, docField)); } } else { metaFields = Collections.emptyMap(); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 4d2954d914e..e419abf1d64 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -55,7 +55,6 @@ import org.elasticsearch.index.analysis.TokenizerFactory; import org.elasticsearch.index.mapper.Mapper.BuilderContext; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.similarity.SimilarityService; -import org.elasticsearch.indices.IndicesModule; import org.elasticsearch.indices.InvalidTypeNameException; import org.elasticsearch.indices.mapper.MapperRegistry; import org.elasticsearch.search.suggest.completion.context.ContextMapping; @@ -63,6 +62,7 @@ import org.elasticsearch.search.suggest.completion.context.ContextMapping; import java.io.Closeable; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -119,6 +119,11 @@ public class MapperService extends AbstractIndexComponent implements Closeable { public static final Setting INDEX_MAPPER_DYNAMIC_SETTING = Setting.boolSetting("index.mapper.dynamic", INDEX_MAPPER_DYNAMIC_DEFAULT, Property.Dynamic, Property.IndexScope, Property.Deprecated); + // Deprecated set of meta-fields, for checking if a field is meta, use an instance method isMetadataField instead + @Deprecated + public static final Set META_FIELDS_BEFORE_7DOT8 = + Collections.unmodifiableSet(new HashSet<>(Arrays.asList( + "_id", IgnoredFieldMapper.NAME, "_index", "_routing", "_size", "_timestamp", "_ttl", "_type"))); private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(MapperService.class)); static final String DEFAULT_MAPPING_ERROR_MESSAGE = "[_default_] mappings are not allowed on new indices and should no " + @@ -804,22 +809,6 @@ public class MapperService extends AbstractIndexComponent implements Closeable { indexAnalyzers.close(); } - /** - * @return Whether a field is a metadata field - * Deserialization of SearchHit objects sent from pre 7.8 nodes and GetResults objects sent from pre 7.3 nodes, - * uses this method to divide fields into meta and document fields. - * TODO: remove in v 9.0 - * @deprecated Use an instance method isMetadataField instead - */ - @Deprecated - public static boolean isMetadataFieldStatic(String fieldName) { - if (IndicesModule.getBuiltInMetadataFields().contains(fieldName)) { - return true; - } - // if a node had Size Plugin installed, _size field should also be considered a meta-field - return fieldName.equals("_size"); - } - /** * @return Whether a field is a metadata field. * this method considers all mapper plugins diff --git a/server/src/main/java/org/elasticsearch/search/SearchHit.java b/server/src/main/java/org/elasticsearch/search/SearchHit.java index a3afb7baa65..da9fe5fe9cd 100644 --- a/server/src/main/java/org/elasticsearch/search/SearchHit.java +++ b/server/src/main/java/org/elasticsearch/search/SearchHit.java @@ -168,7 +168,7 @@ public final class SearchHit implements Writeable, ToXContentObject, Iterable(); metaFields = new HashMap<>(); fields.forEach((fieldName, docField) -> - (MapperService.isMetadataFieldStatic(fieldName) ? metaFields : documentFields).put(fieldName, docField)); + (MapperService.META_FIELDS_BEFORE_7DOT8.contains(fieldName) ? metaFields : documentFields).put(fieldName, docField)); } int size = in.readVInt(); diff --git a/server/src/test/java/org/elasticsearch/search/SearchHitsTests.java b/server/src/test/java/org/elasticsearch/search/SearchHitsTests.java index a65c0601531..4ef33df00e2 100644 --- a/server/src/test/java/org/elasticsearch/search/SearchHitsTests.java +++ b/server/src/test/java/org/elasticsearch/search/SearchHitsTests.java @@ -22,11 +22,9 @@ package org.elasticsearch.search; import org.apache.lucene.search.SortField; import org.apache.lucene.search.TotalHits; import org.apache.lucene.util.TestUtil; -import org.elasticsearch.Version; import org.elasticsearch.action.OriginalIndices; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.lucene.LuceneTests; import org.elasticsearch.common.text.Text; @@ -39,10 +37,8 @@ import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.test.AbstractSerializingTestCase; -import org.elasticsearch.test.VersionUtils; import java.io.IOException; -import java.util.Base64; import java.util.Collections; import java.util.function.Predicate; @@ -271,37 +267,4 @@ public class SearchHitsTests extends AbstractSerializingTestCase { } } - - public void testReadFromPre6_6_0() throws IOException { - try (StreamInput in = StreamInput.wrap(Base64.getDecoder().decode("AQC/gAAAAAA="))) { - in.setVersion(VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, VersionUtils.getPreviousVersion(Version.V_6_6_0))); - SearchHits searchHits = new SearchHits(in); - assertEquals(0, searchHits.getHits().length); - assertNotNull(searchHits.getTotalHits()); - assertEquals(0L, searchHits.getTotalHits().value); - assertEquals(TotalHits.Relation.EQUAL_TO, searchHits.getTotalHits().relation); - assertEquals(-1F, searchHits.getMaxScore(), 0F); - assertNull(searchHits.getSortFields()); - assertNull(searchHits.getCollapseField()); - assertNull(searchHits.getCollapseValues()); - } - } - - public void testSerializationPre6_6_0() throws IOException { - Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, VersionUtils.getPreviousVersion(Version.V_6_6_0)); - SearchHits original = createTestItem(randomFrom(XContentType.values()), false, true, TotalHits.Relation.EQUAL_TO); - SearchHits deserialized = copyInstance(original, version); - assertArrayEquals(original.getHits(), deserialized.getHits()); - assertEquals(original.getMaxScore(), deserialized.getMaxScore(), 0F); - if (original.getTotalHits() == null) { - assertNull(deserialized.getTotalHits()); - } else { - assertNotNull(deserialized.getTotalHits()); - assertEquals(original.getTotalHits().value, deserialized.getTotalHits().value); - assertEquals(original.getTotalHits().relation, deserialized.getTotalHits().relation); - } - assertNull(deserialized.getSortFields()); - assertNull(deserialized.getCollapseField()); - assertNull(deserialized.getCollapseValues()); - } } diff --git a/server/src/test/java/org/elasticsearch/search/SearchSortValuesTests.java b/server/src/test/java/org/elasticsearch/search/SearchSortValuesTests.java index 695da60af61..8cec44618c9 100644 --- a/server/src/test/java/org/elasticsearch/search/SearchSortValuesTests.java +++ b/server/src/test/java/org/elasticsearch/search/SearchSortValuesTests.java @@ -20,9 +20,7 @@ package org.elasticsearch.search; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.Version; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.lucene.LuceneTests; import org.elasticsearch.common.xcontent.ToXContent; @@ -32,11 +30,9 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.AbstractSerializingTestCase; import org.elasticsearch.test.RandomObjects; -import org.elasticsearch.test.VersionUtils; import java.io.IOException; import java.util.Arrays; -import java.util.Base64; public class SearchSortValuesTests extends AbstractSerializingTestCase { @@ -140,22 +136,4 @@ public class SearchSortValuesTests extends AbstractSerializingTestCase