diff --git a/docs/reference/mapping/types/geo-shape.asciidoc b/docs/reference/mapping/types/geo-shape.asciidoc index 92ee2d1065100..1cebbd13ce90a 100644 --- a/docs/reference/mapping/types/geo-shape.asciidoc +++ b/docs/reference/mapping/types/geo-shape.asciidoc @@ -21,61 +21,6 @@ type. |======================================================================= |Option |Description| Default -|`tree |deprecated[6.6, PrefixTrees no longer used] Name of the PrefixTree -implementation to be used: `geohash` for GeohashPrefixTree and `quadtree` -for QuadPrefixTree. Note: This parameter is only relevant for `term` and -`recursive` strategies. -| `quadtree` - -|`precision` |deprecated[6.6, PrefixTrees no longer used] This parameter may -be used instead of `tree_levels` to set an appropriate value for the -`tree_levels` parameter. The value specifies the desired precision and -Elasticsearch will calculate the best tree_levels value to honor this -precision. The value should be a number followed by an optional distance -unit. Valid distance units include: `in`, `inch`, `yd`, `yard`, `mi`, -`miles`, `km`, `kilometers`, `m`,`meters`, `cm`,`centimeters`, `mm`, -`millimeters`. Note: This parameter is only relevant for `term` and -`recursive` strategies. -| `50m` - -|`tree_levels` |deprecated[6.6, PrefixTrees no longer used] Maximum number -of layers to be used by the PrefixTree. This can be used to control the -precision of shape representations andtherefore how many terms are -indexed. Defaults to the default value of the chosen PrefixTree -implementation. Since this parameter requires a certain level of -understanding of the underlying implementation, users may use the -`precision` parameter instead. However, Elasticsearch only uses the -tree_levels parameter internally and this is what is returned via the -mapping API even if you use the precision parameter. Note: This parameter -is only relevant for `term` and `recursive` strategies. -| various - -|`strategy` |deprecated[6.6, PrefixTrees no longer used] The strategy -parameter defines the approach for how to represent shapes at indexing -and search time. It also influences the capabilities available so it -is recommended to let Elasticsearch set this parameter automatically. -There are two strategies available: `recursive`, and `term`. -Recursive and Term strategies are deprecated and will be removed in a -future version. While they are still available, the Term strategy -supports point types only (the `points_only` parameter will be -automatically set to true) while Recursive strategy supports all -shape types. (IMPORTANT: see <> for more -detailed information about these strategies) -| `recursive` - -|`distance_error_pct` |deprecated[6.6, PrefixTrees no longer used] Used as a -hint to the PrefixTree about how precise it should be. Defaults to 0.025 (2.5%) -with 0.5 as the maximum supported value. PERFORMANCE NOTE: This value will -default to 0 if a `precision` or `tree_level` definition is explicitly defined. -This guarantees spatial precision at the level defined in the mapping. This can -lead to significant memory usage for high resolution shapes with low error -(e.g., large shapes at 1m with < 0.001 error). To improve indexing performance -(at the cost of query accuracy) explicitly define `tree_level` or `precision` -along with a reasonable `distance_error_pct`, noting that large shapes will have -greater false positives. Note: This parameter is only relevant for `term` and -`recursive` strategies. -| `0.025` - |`orientation` |Optionally define how to interpret vertex order for polygons / multipolygons. This parameter defines one of two coordinate system rules (Right-hand or Left-hand) each of which can be specified in three @@ -88,15 +33,6 @@ sets vertex order for the coordinate list of a geo_shape field but can be overridden in each individual GeoJSON or WKT document. | `ccw` -|`points_only` |deprecated[6.6, PrefixTrees no longer used] Setting this option to -`true` (defaults to `false`) configures the `geo_shape` field type for point -shapes only (NOTE: Multi-Points are not yet supported). This optimizes index and -search performance for the `geohash` and `quadtree` when it is known that only points -will be indexed. At present geo_shape queries can not be executed on `geo_point` -field types. This option bridges the gap by improving point performance on a -`geo_shape` field so that `geo_shape` queries are optimal on a point only field. -| `false` - |`ignore_malformed` |If true, malformed GeoJSON or WKT shapes are ignored. If false (default), malformed GeoJSON and WKT shapes throw an exception and reject the entire document. @@ -114,84 +50,13 @@ and reject the whole document. [[geoshape-indexing-approach]] [float] -==== Indexing approach +==== Indexing approach and Accuracy GeoShape types are indexed by decomposing the shape into a triangular mesh and indexing each triangle as a 7 dimension point in a BKD tree. This provides near perfect spatial resolution (down to 1e-7 decimal degree precision) since all spatial relations are computed using an encoded vector representation of the -original shape instead of a raster-grid representation as used by the -<> indexing approach. Performance of the tessellator primarily -depends on the number of vertices that define the polygon/multi-polygon. While -this is the default indexing technique prefix trees can still be used by setting -the `tree` or `strategy` parameters according to the appropriate -<>. Note that these parameters are now deprecated -and will be removed in a future version. - -[[prefix-trees]] -[float] -==== Prefix trees - -deprecated[6.6, PrefixTrees no longer used] To efficiently represent shapes in -an inverted index, Shapes are converted into a series of hashes representing -grid squares (commonly referred to as "rasters") using implementations of a -PrefixTree. The tree notion comes from the fact that the PrefixTree uses multiple -grid layers, each with an increasing level of precision to represent the Earth. -This can be thought of as increasing the level of detail of a map or image at higher -zoom levels. Since this approach causes precision issues with indexed shape, it has -been deprecated in favor of a vector indexing approach that indexes the shapes as a -triangular mesh (see <>). - -Multiple PrefixTree implementations are provided: - -* GeohashPrefixTree - Uses -http://en.wikipedia.org/wiki/Geohash[geohashes] for grid squares. -Geohashes are base32 encoded strings of the bits of the latitude and -longitude interleaved. So the longer the hash, the more precise it is. -Each character added to the geohash represents another tree level and -adds 5 bits of precision to the geohash. A geohash represents a -rectangular area and has 32 sub rectangles. The maximum number of levels -in Elasticsearch is 24; the default is 9. -* QuadPrefixTree - Uses a -http://en.wikipedia.org/wiki/Quadtree[quadtree] for grid squares. -Similar to geohash, quad trees interleave the bits of the latitude and -longitude the resulting hash is a bit set. A tree level in a quad tree -represents 2 bits in this bit set, one for each coordinate. The maximum -number of levels for the quad trees in Elasticsearch is 29; the default is 21. - -[[spatial-strategy]] -[float] -===== Spatial strategies -deprecated[6.6, PrefixTrees no longer used] The indexing implementation -selected relies on a SpatialStrategy for choosing how to decompose the shapes -(either as grid squares or a tessellated triangular mesh). Each strategy -answers the following: - -* What type of Shapes can be indexed? -* What types of Query Operations and Shapes can be used? -* Does it support more than one Shape per field? - -The following Strategy implementations (with corresponding capabilities) -are provided: - -[cols="<,<,<,<",options="header",] -|======================================================================= -|Strategy |Supported Shapes |Supported Queries |Multiple Shapes - -|`recursive` |<> |`INTERSECTS`, `DISJOINT`, `WITHIN`, `CONTAINS` |Yes -|`term` |<> |`INTERSECTS` |Yes - -|======================================================================= - -[float] -===== Accuracy - -`Recursive` and `Term` strategies do not provide 100% accuracy and depending on -how they are configured it may return some false positives for `INTERSECTS`, -`WITHIN` and `CONTAINS` queries, and some false negatives for `DISJOINT` queries. -To mitigate this, it is important to select an appropriate value for the tree_levels -parameter and to adjust expectations accordingly. For example, a point may be near -the border of a particular grid cell and may thus not match a query that only matches -the cell right next to it -- even though the shape is very close to the point. +original shape. Performance of the tessellator primarily depends on the number of +vertices that define the polygon/multi-polygon. [float] ===== Example @@ -215,27 +80,7 @@ PUT /example // TESTSETUP This mapping definition maps the location field to the geo_shape -type using the default vector implementation. It provides -approximately 1e-7 decimal degree precision. - -[float] -===== Performance considerations with Prefix Trees - -deprecated[6.6, PrefixTrees no longer used] With prefix trees, -Elasticsearch uses the paths in the tree as terms in the inverted index -and in queries. The higher the level (and thus the precision), the more -terms are generated. Of course, calculating the terms, keeping them in -memory, and storing them on disk all have a price. Especially with higher -tree levels, indices can become extremely large even with a modest amount -of data. Additionally, the size of the features also matters. Big, complex -polygons can take up a lot of space at higher tree levels. Which setting -is right depends on the use case. Generally one trades off accuracy against -index size and query performance. - -The defaults in Elasticsearch for both implementations are a compromise -between index size and a reasonable level of precision of 50m at the -equator. This allows for indexing tens of millions of shapes without -overly bloating the resulting index too much relative to the input size. +type with approximately 1e-7 decimal degree spatial precision. [[input-structure]] [float] @@ -624,34 +469,6 @@ POST /example/doc -------------------------------------------------- // CONSOLE -[float] -===== Circle - -Elasticsearch supports a `circle` type, which consists of a center -point with a radius. Note that this circle representation can only -be indexed when using the `recursive` Prefix Tree strategy. For -the default <> circles should be approximated using -a `POLYGON`. - -[source,js] --------------------------------------------------- -POST /example/doc -{ - "location" : { - "type" : "circle", - "coordinates" : [101.0, 1.0], - "radius" : "100m" - } -} --------------------------------------------------- -// CONSOLE -// TEST[skip:not supported in default] - -Note: The inner `radius` field is required. If not specified, then -the units of the `radius` will default to `METERS`. - -*NOTE:* Neither GeoJSON or WKT support a point-radius circle type. - [float] ==== Sorting and Retrieving index Shapes diff --git a/docs/reference/migration/migrate_7_0/mappings.asciidoc b/docs/reference/migration/migrate_7_0/mappings.asciidoc index e4d38d9a64374..beb118396c47f 100644 --- a/docs/reference/migration/migrate_7_0/mappings.asciidoc +++ b/docs/reference/migration/migrate_7_0/mappings.asciidoc @@ -54,21 +54,7 @@ An error will now be thrown when unknown configuration options are provided to similarities. Such unknown parameters were ignored before. [float] -==== Changed default `geo_shape` indexing strategy +==== prohibit use of `geo_shape` prefix tree parameters for new indexes -`geo_shape` types now default to using a vector indexing approach based on Lucene's new -`LatLonShape` field type. This indexes shapes as a triangular mesh instead of decomposing -them into individual grid cells. To index using legacy prefix trees the `tree` parameter -must be explicitly set to one of `quadtree` or `geohash`. Note that these strategies are -now deprecated and will be removed in a future version. - -IMPORTANT NOTE: If using timed index creation from templates, the `geo_shape` mapping -should also be changed in the template to explicitly define `tree` to one of `geohash` -or `quadtree`. This will ensure compatibility with previously created indexes. - -[float] -==== deprecated `geo_shape` parameters - -The following type parameters are deprecated for the `geo_shape` field type: `tree`, -`precision`, `tree_levels`, `distance_error_pct`, `points_only`, and `strategy`. They -will be removed in a future version. \ No newline at end of file +The following type parameters are now prohibited for the `geo_shape` field type: `tree`, +`precision`, `tree_levels`, `distance_error_pct`, `points_only`, and `strategy`. \ No newline at end of file diff --git a/docs/reference/query-dsl/geo-shape-query.asciidoc b/docs/reference/query-dsl/geo-shape-query.asciidoc index f796881d520c6..acf717c77f900 100644 --- a/docs/reference/query-dsl/geo-shape-query.asciidoc +++ b/docs/reference/query-dsl/geo-shape-query.asciidoc @@ -5,12 +5,7 @@ Filter documents indexed using the `geo_shape` type. Requires the <>. -The `geo_shape` query uses the same grid square representation as the -`geo_shape` mapping to find documents that have a shape that intersects -with the query shape. It will also use the same Prefix Tree configuration -as defined for the field mapping. - -The query supports two ways of defining the query shape, either by +The `geo_shape` query supports two ways of defining the query shape, either by providing a whole shape definition, or by referencing the name of a shape pre-indexed in another index. Both formats are defined below with examples. @@ -145,9 +140,6 @@ GET /example/_search ==== Spatial Relations -The <> mapping parameter determines -which spatial relation operators may be used at search time. - The following is a complete list of spatial relation operators available: * `INTERSECTS` - (default) Return all documents whose `geo_shape` field @@ -156,9 +148,6 @@ intersects the query geometry. has nothing in common with the query geometry. * `WITHIN` - Return all documents whose `geo_shape` field is within the query geometry. -* `CONTAINS` - Return all documents whose `geo_shape` field -contains the query geometry. Note: this is only supported using the -`recursive` Prefix Tree Strategy deprecated[6.6] [float] ==== Ignore Unmapped diff --git a/server/src/main/java/org/elasticsearch/index/mapper/BaseGeoShapeFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/BaseGeoShapeFieldMapper.java index ea30f1c5c2312..c21461482c82b 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/BaseGeoShapeFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/BaseGeoShapeFieldMapper.java @@ -171,7 +171,7 @@ public Mapper.Builder parse(String name, Map node, ParserContext Map.Entry entry = iterator.next(); String fieldName = entry.getKey(); Object fieldNode = entry.getValue(); - if (DeprecatedParameters.parse(name, fieldName, fieldNode, deprecatedParameters)) { + if (DeprecatedParameters.parse(parserContext, name, fieldName, fieldNode, deprecatedParameters)) { parsedDeprecatedParams = true; iterator.remove(); } else if (Names.ORIENTATION.match(fieldName, LoggingDeprecationHandler.INSTANCE)) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapper.java index c0b931225b8e6..076999181c0d1 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapper.java @@ -46,6 +46,7 @@ import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.support.XContentMapValues; +import org.elasticsearch.index.mapper.Mapper.TypeParser.ParserContext; import org.locationtech.spatial4j.shape.Point; import org.locationtech.spatial4j.shape.Shape; import org.locationtech.spatial4j.shape.jts.JtsGeometry; @@ -144,24 +145,25 @@ public void setDistanceErrorPct(double distanceErrorPct) { this.distanceErrorPct = distanceErrorPct; } - public static boolean parse(String name, String fieldName, Object fieldNode, DeprecatedParameters deprecatedParameters) { + public static boolean parse(ParserContext parserContext, String name, String fieldName, Object fieldNode, + DeprecatedParameters deprecatedParameters) { if (Names.STRATEGY.match(fieldName, LoggingDeprecationHandler.INSTANCE)) { - checkPrefixTreeSupport(fieldName); + checkPrefixTreeSupport(parserContext, fieldName); deprecatedParameters.setSpatialStrategy(SpatialStrategy.fromString(fieldNode.toString())); } else if (Names.TREE.match(fieldName, LoggingDeprecationHandler.INSTANCE)) { - checkPrefixTreeSupport(fieldName); + checkPrefixTreeSupport(parserContext, fieldName); deprecatedParameters.setTree(fieldNode.toString()); } else if (Names.TREE_LEVELS.match(fieldName, LoggingDeprecationHandler.INSTANCE)) { - checkPrefixTreeSupport(fieldName); + checkPrefixTreeSupport(parserContext, fieldName); deprecatedParameters.setTreeLevels(Integer.parseInt(fieldNode.toString())); } else if (Names.PRECISION.match(fieldName, LoggingDeprecationHandler.INSTANCE)) { - checkPrefixTreeSupport(fieldName); + checkPrefixTreeSupport(parserContext, fieldName); deprecatedParameters.setPrecision(fieldNode.toString()); } else if (Names.DISTANCE_ERROR_PCT.match(fieldName, LoggingDeprecationHandler.INSTANCE)) { - checkPrefixTreeSupport(fieldName); + checkPrefixTreeSupport(parserContext, fieldName); deprecatedParameters.setDistanceErrorPct(Double.parseDouble(fieldNode.toString())); } else if (Names.POINTS_ONLY.match(fieldName, LoggingDeprecationHandler.INSTANCE)) { - checkPrefixTreeSupport(fieldName); + checkPrefixTreeSupport(parserContext, fieldName); deprecatedParameters.setPointsOnly( XContentMapValues.nodeBooleanValue(fieldNode, name + "." + DeprecatedParameters.Names.POINTS_ONLY)); } else { @@ -170,8 +172,9 @@ public static boolean parse(String name, String fieldName, Object fieldNode, Dep return true; } - private static void checkPrefixTreeSupport(String fieldName) { - if (ShapesAvailability.JTS_AVAILABLE == false || ShapesAvailability.SPATIAL4J_AVAILABLE == false) { + private static void checkPrefixTreeSupport(ParserContext parserContext, String fieldName) { + if (parserContext.indexVersionCreated().onOrAfter(Version.V_7_0_0) + || ShapesAvailability.JTS_AVAILABLE == false || ShapesAvailability.SPATIAL4J_AVAILABLE == false) { throw new ElasticsearchParseException("Field parameter [{}] is not supported for [{}] field type", fieldName, CONTENT_TYPE); } @@ -552,7 +555,7 @@ protected void doXContentBody(XContentBuilder builder, boolean includeDefaults, DistanceUnit.METERS.toString(50)); } - if (indexCreatedVersion.onOrAfter(Version.V_7_0_0)) { + if (indexCreatedVersion.onOrAfter(Version.V_6_6_0)) { builder.field(DeprecatedParameters.Names.STRATEGY.getPreferredName(), fieldType().strategy().getStrategyName()); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java b/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java index 2fb4cfeb81dbf..20c49c00935e3 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java @@ -87,7 +87,7 @@ public ExternalMapper build(BuilderContext context) { BinaryFieldMapper binMapper = binBuilder.build(context); BooleanFieldMapper boolMapper = boolBuilder.build(context); GeoPointFieldMapper pointMapper = latLonPointBuilder.build(context); - BaseGeoShapeFieldMapper shapeMapper = (context.indexCreatedVersion().before(Version.V_7_0_0)) + BaseGeoShapeFieldMapper shapeMapper = (context.indexCreatedVersion().before(Version.V_6_6_0)) ? legacyShapeBuilder.build(context) : shapeBuilder.build(context); FieldMapper stringMapper = (FieldMapper)stringBuilder.build(context); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/FieldFilterMapperPluginTests.java b/server/src/test/java/org/elasticsearch/index/mapper/FieldFilterMapperPluginTests.java index 07a80a31debb6..2a3c56b8cf9b3 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/FieldFilterMapperPluginTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FieldFilterMapperPluginTests.java @@ -305,9 +305,7 @@ public Function> getFieldFilter() { " \"type\": \"geo_point\"\n" + " },\n" + " \"area_visible\": {\n" + - " \"type\": \"geo_shape\", \n" + - " \"tree\": \"quadtree\",\n" + - " \"precision\": \"1m\"\n" + + " \"type\": \"geo_shape\"\n" + " }\n" + " }\n" + " },\n" + diff --git a/server/src/test/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapperTests.java index d53eb0bcac134..aa8459090e554 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapperTests.java @@ -23,17 +23,21 @@ import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree; import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree; import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.Version; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Strings; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.geo.GeoUtils; import org.elasticsearch.common.geo.builders.ShapeBuilder; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.InternalSettingsPlugin; +import org.elasticsearch.test.VersionUtils; import java.io.IOException; import java.util.Collection; @@ -47,6 +51,11 @@ public class LegacyGeoShapeFieldMapperTests extends ESSingleNodeTestCase { + @Override + protected boolean forbidPrivateIndexSettings() { + return false; + } + @Override protected Collection> getPlugins() { return pluginList(InternalSettingsPlugin.class); @@ -60,7 +69,9 @@ public void testDefaultConfiguration() throws IOException { .endObject().endObject() .endObject().endObject()); - DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_6_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + DocumentMapper defaultMapper = createIndex("test", indexSettings).mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("location"); assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); @@ -91,7 +102,9 @@ public void testOrientationParsing() throws IOException { .endObject().endObject() .endObject().endObject()); - DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + DocumentMapper defaultMapper = createIndex("test", indexSettings).mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("location"); assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); @@ -110,7 +123,7 @@ public void testOrientationParsing() throws IOException { .endObject().endObject() .endObject().endObject()); - defaultMapper = createIndex("test2").mapperService().documentMapperParser() + defaultMapper = createIndex("test2", indexSettings).mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); fieldMapper = defaultMapper.mappers().getMapper("location"); assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); @@ -134,7 +147,9 @@ public void testCoerceParsing() throws IOException { .endObject().endObject() .endObject().endObject()); - DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_6_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + DocumentMapper defaultMapper = createIndex("test", indexSettings).mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("location"); assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); @@ -151,7 +166,7 @@ public void testCoerceParsing() throws IOException { .endObject().endObject() .endObject().endObject()); - defaultMapper = createIndex("test2").mapperService().documentMapperParser() + defaultMapper = createIndex("test2", indexSettings).mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); fieldMapper = defaultMapper.mappers().getMapper("location"); assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); @@ -174,7 +189,9 @@ public void testIgnoreZValue() throws IOException { .endObject().endObject() .endObject().endObject()); - DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_6_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + DocumentMapper defaultMapper = createIndex("test", indexSettings).mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("location"); assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); @@ -191,7 +208,7 @@ public void testIgnoreZValue() throws IOException { .endObject().endObject() .endObject().endObject()); - defaultMapper = createIndex("test2").mapperService().documentMapperParser() + defaultMapper = createIndex("test2", indexSettings).mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); fieldMapper = defaultMapper.mappers().getMapper("location"); assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); @@ -213,7 +230,9 @@ public void testIgnoreMalformedParsing() throws IOException { .endObject().endObject() .endObject().endObject()); - DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_6_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + DocumentMapper defaultMapper = createIndex("test", indexSettings).mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("location"); assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); @@ -230,7 +249,7 @@ public void testIgnoreMalformedParsing() throws IOException { .endObject().endObject() .endObject().endObject()); - defaultMapper = createIndex("test2").mapperService().documentMapperParser() + defaultMapper = createIndex("test2", indexSettings).mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); fieldMapper = defaultMapper.mappers().getMapper("location"); assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); @@ -251,7 +270,9 @@ public void testGeohashConfiguration() throws IOException { .endObject().endObject() .endObject().endObject()); - DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_6_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + DocumentMapper defaultMapper = createIndex("test", indexSettings).mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("location"); assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); @@ -276,7 +297,9 @@ public void testQuadtreeConfiguration() throws IOException { .endObject().endObject() .endObject().endObject()); - DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_6_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + DocumentMapper defaultMapper = createIndex("test", indexSettings).mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("location"); assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); @@ -301,7 +324,9 @@ private void assertFieldWarnings(String... fieldNames) { } public void testLevelPrecisionConfiguration() throws IOException { - DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_6_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + DocumentMapperParser parser = createIndex("test", indexSettings).mapperService().documentMapperParser(); { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1") @@ -435,7 +460,9 @@ public void testPointsOnlyOption() throws IOException { .endObject().endObject() .endObject().endObject()); - DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_6_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + DocumentMapper defaultMapper = createIndex("test", indexSettings).mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("location"); assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); @@ -449,7 +476,9 @@ public void testPointsOnlyOption() throws IOException { } public void testLevelDefaults() throws IOException { - DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_6_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + DocumentMapperParser parser = createIndex("test", indexSettings).mapperService().documentMapperParser(); { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1") .startObject("properties").startObject("location") @@ -504,7 +533,9 @@ public void testGeoShapeMapperMerge() throws Exception { .field("precision", "1m").field("tree_levels", 8).field("distance_error_pct", 0.01) .field("orientation", "ccw") .endObject().endObject().endObject().endObject()); - MapperService mapperService = createIndex("test").mapperService(); + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_6_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper docMapper = mapperService.merge("type", new CompressedXContent(stage1Mapping), MapperService.MergeReason.MAPPING_UPDATE); String stage2Mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") @@ -569,7 +600,9 @@ public void testEmptyName() throws Exception { .field("tree", "quadtree") .endObject().endObject() .endObject().endObject()); - DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_6_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + DocumentMapperParser parser = createIndex("test", indexSettings).mapperService().documentMapperParser(); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> parser.parse("type1", new CompressedXContent(mapping)) @@ -579,7 +612,9 @@ public void testEmptyName() throws Exception { } public void testSerializeDefaults() throws Exception { - DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_6_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + DocumentMapperParser parser = createIndex("test", indexSettings).mapperService().documentMapperParser(); { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1") .startObject("properties").startObject("location") @@ -657,7 +692,9 @@ public void testPointsOnlyDefaultsWithTermStrategy() throws IOException { .endObject().endObject() .endObject().endObject()); - DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_6_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + DocumentMapper defaultMapper = createIndex("test", indexSettings).mapperService().documentMapperParser() .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("location"); assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); @@ -686,7 +723,9 @@ public void testPointsOnlyFalseWithTermStrategy() throws Exception { .endObject().endObject() .endObject().endObject()); - DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_6_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + DocumentMapperParser parser = createIndex("test", indexSettings).mapperService().documentMapperParser(); ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> parser.parse("type1", new CompressedXContent(mapping)) diff --git a/server/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java b/server/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java index a64f98df5a6eb..270771e017fdf 100644 --- a/server/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java +++ b/server/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java @@ -21,9 +21,11 @@ import com.carrotsearch.randomizedtesting.generators.RandomNumbers; import org.apache.lucene.geo.GeoTestUtil; +import org.elasticsearch.Version; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.CheckedSupplier; import org.elasticsearch.common.Strings; import org.elasticsearch.common.geo.ShapeRelation; @@ -42,12 +44,13 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.mapper.LegacyGeoShapeFieldMapper; -import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.query.ExistsQueryBuilder; import org.elasticsearch.index.query.GeoShapeQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.test.ESSingleNodeTestCase; +import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.geo.RandomShapeGenerator; +import org.junit.Ignore; import org.locationtech.jts.geom.Coordinate; import org.locationtech.spatial4j.shape.Rectangle; @@ -58,7 +61,6 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.geoIntersectionQuery; import static org.elasticsearch.index.query.QueryBuilders.geoShapeQuery; -import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.test.geo.RandomShapeGenerator.createGeometryCollectionWithin; import static org.elasticsearch.test.geo.RandomShapeGenerator.xRandomPoint; import static org.elasticsearch.test.geo.RandomShapeGenerator.xRandomRectangle; @@ -75,11 +77,16 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase { LegacyGeoShapeFieldMapper.DeprecatedParameters.PrefixTrees.QUADTREE }; - private XContentBuilder createMapping() throws Exception { + @Override + protected boolean forbidPrivateIndexSettings() { + return false; + } + + private XContentBuilder createMapping(boolean prefixTreeSupported) throws Exception { XContentBuilder xcb = XContentFactory.jsonBuilder().startObject().startObject("type1") .startObject("properties").startObject("location") .field("type", "geo_shape"); - if (randomBoolean()) { + if (prefixTreeSupported && randomBoolean()) { xcb = xcb.field("tree", randomFrom(PREFIX_TREES)) .field("strategy", randomFrom(SpatialStrategy.RECURSIVE, SpatialStrategy.TERM)); } @@ -89,8 +96,12 @@ private XContentBuilder createMapping() throws Exception { } public void testNullShape() throws Exception { - String mapping = Strings.toString(createMapping()); - client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).get(); + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + + String mapping = Strings.toString(createMapping(version.before(Version.V_7_0_0))); + client().admin().indices().prepareCreate("test").setSettings(indexSettings) + .addMapping("type1", mapping, XContentType.JSON).get(); ensureGreen(); client().prepareIndex("test", "type1", "aNullshape").setSource("{\"location\": null}", XContentType.JSON) @@ -100,8 +111,12 @@ public void testNullShape() throws Exception { } public void testIndexPointsFilterRectangle() throws Exception { - String mapping = Strings.toString(createMapping()); - client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).get(); + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + + String mapping = Strings.toString(createMapping(version.before(Version.V_7_0_0))); + client().admin().indices().prepareCreate("test").setSettings(indexSettings) + .addMapping("type1", mapping, XContentType.JSON).get(); ensureGreen(); client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() @@ -178,8 +193,12 @@ public void testEdgeCases() throws Exception { } public void testIndexedShapeReference() throws Exception { - String mapping = Strings.toString(createMapping()); - client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).get(); + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + + String mapping = Strings.toString(createMapping(version.before(Version.V_7_0_0))); + client().admin().indices().prepareCreate("test").setSettings(indexSettings) + .addMapping("type1", mapping, XContentType.JSON).get(); createIndex("shapes"); ensureGreen(); @@ -215,8 +234,11 @@ public void testIndexedShapeReference() throws Exception { } public void testIndexedShapeReferenceSourceDisabled() throws Exception { - XContentBuilder mapping = createMapping(); - client().admin().indices().prepareCreate("test").addMapping("type1", mapping).get(); + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + + XContentBuilder mapping = createMapping(version.before(Version.V_7_0_0)); + client().admin().indices().prepareCreate("test").setSettings(indexSettings).addMapping("type1", mapping).get(); createIndex("shapes", Settings.EMPTY, "shape_type", "_source", "enabled=false"); ensureGreen(); @@ -330,6 +352,9 @@ public void testShapeFetchingPath() throws Exception { } public void testQueryRandomGeoCollection() throws Exception { + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + // Create a random geometry collection. GeometryCollectionBuilder gcb = RandomShapeGenerator.createGeometryCollection(random()); org.apache.lucene.geo.Polygon randomPoly = GeoTestUtil.nextPolygon(); @@ -341,12 +366,12 @@ public void testQueryRandomGeoCollection() throws Exception { logger.info("Created Random GeometryCollection containing {} shapes", gcb.numShapes()); - if (randomBoolean()) { - client().admin().indices().prepareCreate("test") - .addMapping("type", "location", "type=geo_shape").get(); - } else { - client().admin().indices().prepareCreate("test") + if (version.before(Version.V_7_0_0)) { + client().admin().indices().prepareCreate("test").setSettings(indexSettings) .addMapping("type", "location", "type=geo_shape,tree=quadtree").get(); + } else { + client().admin().indices().prepareCreate("test").setSettings(indexSettings) + .addMapping("type", "location", "type=geo_shape").get(); } XContentBuilder docSource = gcb.toXContent(jsonBuilder().startObject().field("location"), null).endObject(); @@ -362,7 +387,10 @@ public void testQueryRandomGeoCollection() throws Exception { } public void testRandomGeoCollectionQuery() throws Exception { - boolean usePrefixTrees = randomBoolean(); + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + + boolean usePrefixTrees = version.before(Version.V_7_0_0); // Create a random geometry collection to index. GeometryCollectionBuilder gcb; if (usePrefixTrees) { @@ -389,10 +417,12 @@ public void testRandomGeoCollectionQuery() throws Exception { logger.info("Created Random GeometryCollection containing {} shapes", gcb.numShapes()); if (usePrefixTrees == false) { - client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape") + client().admin().indices().prepareCreate("test").setSettings(indexSettings) + .addMapping("type", "location", "type=geo_shape") .execute().actionGet(); } else { - client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape,tree=quadtree") + client().admin().indices().prepareCreate("test").setSettings(indexSettings) + .addMapping("type", "location", "type=geo_shape,tree=quadtree") .execute().actionGet(); } @@ -412,16 +442,21 @@ public void testRandomGeoCollectionQuery() throws Exception { /** tests querying a random geometry collection with a point */ public void testPointQuery() throws Exception { + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + // Create a random geometry collection to index. GeometryCollectionBuilder gcb = RandomShapeGenerator.createGeometryCollection(random()); double[] pt = new double[] {GeoTestUtil.nextLongitude(), GeoTestUtil.nextLatitude()}; PointBuilder pb = new PointBuilder(pt[0], pt[1]); gcb.shape(pb); - if (randomBoolean()) { - client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape") + if (version.onOrAfter(Version.V_7_0_0)) { + client().admin().indices().prepareCreate("test").setSettings(indexSettings) + .addMapping("type", "location", "type=geo_shape") .execute().actionGet(); } else { - client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape,tree=quadtree") + client().admin().indices().prepareCreate("test").setSettings(indexSettings) + .addMapping("type", "location", "type=geo_shape,tree=quadtree") .execute().actionGet(); } XContentBuilder docSource = gcb.toXContent(jsonBuilder().startObject().field("location"), null).endObject(); @@ -434,6 +469,8 @@ public void testPointQuery() throws Exception { assertHitCount(result, 1); } + // ignore until CONTAINS query support is added + @Ignore public void testContainsShapeQuery() throws Exception { // Create a random geometry collection. Rectangle mbr = xRandomRectangle(random(), xRandomPoint(random()), true); @@ -470,7 +507,10 @@ public void testExistsQuery() throws Exception { client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape") .execute().actionGet(); } else { - client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape,tree=quadtree") + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.V_6_7_0); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + client().admin().indices().prepareCreate("test").setSettings(indexSettings) + .addMapping("type", "location", "type=geo_shape,tree=quadtree") .execute().actionGet(); } @@ -484,8 +524,18 @@ public void testExistsQuery() throws Exception { } public void testShapeFilterWithDefinedGeoCollection() throws Exception { - createIndex("shapes"); - client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape,tree=quadtree") + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + createIndex("shapes", indexSettings); + + String mapping; + if (version.before(Version.V_7_0_0)) { + mapping = "type=geo_shape,tree=quadtree"; + } else { + mapping = "type=geo_shape"; + } + + client().admin().indices().prepareCreate("test").setSettings(indexSettings).addMapping("type", "location", mapping) .get(); XContentBuilder docSource = jsonBuilder().startObject().startObject("location") @@ -553,81 +603,18 @@ public void testShapeFilterWithDefinedGeoCollection() throws Exception { assertHitCount(result, 0); } - public void testPointsOnly() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1") - .startObject("properties").startObject("location") - .field("type", "geo_shape") - .field("tree", randomBoolean() ? "quadtree" : "geohash") - .field("tree_levels", "6") - .field("distance_error_pct", "0.01") - .field("points_only", true) - .endObject().endObject() - .endObject().endObject()); - - client().admin().indices().prepareCreate("geo_points_only").addMapping("type1", mapping, XContentType.JSON).get(); - ensureGreen(); - - ShapeBuilder shape = RandomShapeGenerator.createShape(random()); - try { - client().prepareIndex("geo_points_only", "type1", "1") - .setSource(jsonBuilder().startObject().field("location", shape).endObject()) - .setRefreshPolicy(IMMEDIATE).get(); - } catch (MapperParsingException e) { - // RandomShapeGenerator created something other than a POINT type, verify the correct exception is thrown - assertThat(e.getCause().getMessage(), containsString("is configured for points only")); - return; - } - - // test that point was inserted - SearchResponse response = client().prepareSearch("geo_points_only").setTypes("type1") - .setQuery(geoIntersectionQuery("location", shape)) - .get(); - - assertEquals(1, response.getHits().getTotalHits().value); - } - - public void testPointsOnlyExplicit() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1") - .startObject("properties").startObject("location") - .field("type", "geo_shape") - .field("tree", randomBoolean() ? "quadtree" : "geohash") - .field("tree_levels", "6") - .field("distance_error_pct", "0.01") - .field("points_only", true) - .endObject().endObject() - .endObject().endObject()); - - client().admin().indices().prepareCreate("geo_points_only").addMapping("type1", mapping, XContentType.JSON).get(); - ensureGreen(); - - // MULTIPOINT - ShapeBuilder shape = RandomShapeGenerator.createShape(random(), RandomShapeGenerator.ShapeType.MULTIPOINT); - client().prepareIndex("geo_points_only", "type1", "1") - .setSource(jsonBuilder().startObject().field("location", shape).endObject()) - .setRefreshPolicy(IMMEDIATE).get(); - - // POINT - shape = RandomShapeGenerator.createShape(random(), RandomShapeGenerator.ShapeType.POINT); - client().prepareIndex("geo_points_only", "type1", "2") - .setSource(jsonBuilder().startObject().field("location", shape).endObject()) - .setRefreshPolicy(IMMEDIATE).get(); - - // test that point was inserted - SearchResponse response = client().prepareSearch("geo_points_only").setTypes("type1") - .setQuery(matchAllQuery()) - .get(); - - assertEquals(2, response.getHits().getTotalHits().value); - } - public void testFieldAlias() throws IOException { + Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT); + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); XContentBuilder mapping = XContentFactory.jsonBuilder().startObject() .startObject("type") .startObject("properties") .startObject("location") - .field("type", "geo_shape") - .field("tree", randomBoolean() ? "quadtree" : "geohash") - .endObject() + .field("type", "geo_shape"); + if (version.before(Version.V_7_0_0)) { + mapping = mapping.field("tree", randomBoolean() ? "quadtree" : "geohash"); + } + mapping = mapping.endObject() .startObject("alias") .field("type", "alias") .field("path", "location") @@ -636,7 +623,7 @@ public void testFieldAlias() throws IOException { .endObject() .endObject(); - createIndex("test", Settings.EMPTY, "type", mapping); + createIndex("test", indexSettings, "type", mapping); ShapeBuilder shape = RandomShapeGenerator.createShape(random(), RandomShapeGenerator.ShapeType.MULTIPOINT); client().prepareIndex("test", "type", "1")