diff --git a/server/src/test/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilderTests.java index 0da5382e85ae2..75e2168940b3f 100644 --- a/server/src/test/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilderTests.java @@ -15,7 +15,6 @@ import org.apache.lucene.search.Query; import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.Version; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoUtils; import org.elasticsearch.geo.GeometryTestUtils; @@ -23,7 +22,6 @@ import org.elasticsearch.geometry.utils.Geohash; import org.elasticsearch.index.mapper.GeoPointFieldMapper; import org.elasticsearch.index.mapper.GeoShapeFieldMapper; -import org.elasticsearch.index.mapper.LegacyGeoShapeFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.test.AbstractQueryTestCase; @@ -222,11 +220,7 @@ protected void doAssertLuceneQuery(GeoBoundingBoxQueryBuilder queryBuilder, Quer queryBuilder.topLeft().lon(), queryBuilder.bottomRight().lon()), dvQuery); } else { - if (context.indexVersionCreated().before(Version.V_6_6_0)) { - assertEquals(LegacyGeoShapeFieldMapper.GeoShapeFieldType.class, fieldType.getClass()); - } else { - assertEquals(GeoShapeFieldMapper.GeoShapeFieldType.class, fieldType.getClass()); - } + assertEquals(GeoShapeFieldMapper.GeoShapeFieldType.class, fieldType.getClass()); } } diff --git a/server/src/test/java/org/elasticsearch/index/query/GeoDistanceQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/GeoDistanceQueryBuilderTests.java index 778c8afd03b34..d819f27d1779e 100644 --- a/server/src/test/java/org/elasticsearch/index/query/GeoDistanceQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/GeoDistanceQueryBuilderTests.java @@ -13,8 +13,6 @@ import org.apache.lucene.search.IndexOrDocValuesQuery; import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.util.LuceneTestCase; -import org.elasticsearch.Version; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.geo.GeoDistance; import org.elasticsearch.common.geo.GeoPoint; @@ -22,7 +20,6 @@ import org.elasticsearch.geo.GeometryTestUtils; import org.elasticsearch.index.mapper.GeoPointFieldMapper; import org.elasticsearch.index.mapper.GeoShapeFieldMapper; -import org.elasticsearch.index.mapper.LegacyGeoShapeFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.test.AbstractQueryTestCase; @@ -32,7 +29,6 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.notNullValue; -@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/77857") public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase { @Override @@ -140,11 +136,7 @@ protected void doAssertLuceneQuery(GeoDistanceQueryBuilder queryBuilder, Query q queryBuilder.distance()), dvQuery); } else { - if (context.indexVersionCreated().before(Version.V_6_6_0)) { - assertEquals(LegacyGeoShapeFieldMapper.GeoShapeFieldType.class, fieldType.getClass()); - } else { - assertEquals(GeoShapeFieldMapper.GeoShapeFieldType.class, fieldType.getClass()); - } + assertEquals(GeoShapeFieldMapper.GeoShapeFieldType.class, fieldType.getClass()); } } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java index 5e25f1656f15a..62e37e3c75da4 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java @@ -201,7 +201,8 @@ public Mapper.Builder parse(String name, Map node, MappingParser FieldMapper.Builder builder; boolean ignoreMalformedByDefault = IGNORE_MALFORMED_SETTING.get(parserContext.getSettings()); boolean coerceByDefault = COERCE_SETTING.get(parserContext.getSettings()); - if (LegacyGeoShapeFieldMapper.containsDeprecatedParameter(node.keySet())) { + if (parserContext.indexVersionCreated().before(Version.V_6_6_0) || + LegacyGeoShapeFieldMapper.containsDeprecatedParameter(node.keySet())) { builder = new LegacyGeoShapeFieldMapper.Builder( name, parserContext.indexVersionCreated(), diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapperTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapperTests.java index 5cb563d117004..39b91ba07b2d5 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapperTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapperTests.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.mapper.DocumentMapper; +import org.elasticsearch.index.mapper.LegacyGeoShapeFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.Mapper; import org.elasticsearch.index.mapper.MapperParsingException; @@ -391,6 +392,17 @@ public void testMultiFieldsDeprecationWarning() throws Exception { assertWarnings("Adding multifields to [geo_shape] mappers has no effect and will be forbidden in future"); } + public void testRandomVersionMapping() throws Exception { + Version version = VersionUtils.randomIndexCompatibleVersion(random()); + DocumentMapper defaultMapper = createDocumentMapper(version, fieldMapping(this::minimalMapping)); + Mapper fieldMapper = defaultMapper.mappers().getMapper("field"); + if (version.before(Version.V_6_6_0)) { + assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); + } else { + assertThat(fieldMapper, instanceOf(GeoShapeWithDocValuesFieldMapper.class)); + } + } + public String toXContentString(GeoShapeWithDocValuesFieldMapper mapper, boolean includeDefaults) { if (includeDefaults) { ToXContent.Params params = new ToXContent.MapParams(Collections.singletonMap("include_defaults", "true")); diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/query/GeoShapeWithDocValuesQueryBuilderTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/query/GeoShapeWithDocValuesQueryBuilderTests.java index 57e44cbb87ae8..6cc57abf1777a 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/query/GeoShapeWithDocValuesQueryBuilderTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/query/GeoShapeWithDocValuesQueryBuilderTests.java @@ -10,6 +10,7 @@ import org.apache.lucene.search.ConstantScoreQuery; import org.apache.lucene.search.IndexOrDocValuesQuery; import org.apache.lucene.search.Query; +import org.elasticsearch.Version; import org.elasticsearch.common.Strings; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -41,7 +42,8 @@ protected Collection> getPlugins() { @Override protected void initializeAdditionalMappings(MapperService mapperService) throws IOException { - if (randomBoolean()) { + + if (mapperService.parserContext().indexVersionCreated().before(Version.V_6_6_0) || randomBoolean()) { XContentBuilder mapping = jsonBuilder().startObject().startObject("_doc").startObject("properties") .startObject("test").field("type", "geo_shape").endObject().endObject().endObject().endObject(); mapperService.merge("_doc",