From a920dcd62e50b746f57c5760a56d6d782662e70a Mon Sep 17 00:00:00 2001 From: pgomulka Date: Thu, 24 Jun 2021 12:45:04 +0200 Subject: [PATCH 1/5] geo shape draft --- .../index/query/AbstractGeometryQueryBuilder.java | 12 ++++++++++++ .../xpack/spatial/index/query/ShapeQueryBuilder.java | 1 + 2 files changed, 13 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/index/query/AbstractGeometryQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/AbstractGeometryQueryBuilder.java index c3c1319e914c8..f8795678e1374 100644 --- a/server/src/main/java/org/elasticsearch/index/query/AbstractGeometryQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/AbstractGeometryQueryBuilder.java @@ -15,6 +15,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.client.Client; +import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.geo.GeoJson; @@ -29,6 +30,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.core.RestApiVersion; import org.elasticsearch.geometry.Geometry; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperService; @@ -41,6 +43,9 @@ * Base {@link QueryBuilder} that builds a Geometry Query */ public abstract class AbstractGeometryQueryBuilder> extends AbstractQueryBuilder { + static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Types are deprecated in [geo_shape] queries. " + + "The type should no longer be specified in the [indexed_shape] section."; + private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(AbstractGeometryQueryBuilder.class); public static final String DEFAULT_SHAPE_INDEX_NAME = "shapes"; public static final String DEFAULT_SHAPE_FIELD_NAME = "shape"; @@ -53,6 +58,7 @@ public abstract class AbstractGeometryQueryBuilder Date: Thu, 24 Jun 2021 17:00:16 +0200 Subject: [PATCH 2/5] precommit --- .../xpack/spatial/index/query/ShapeQueryBuilder.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryBuilder.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryBuilder.java index a8b0507c22fd7..c904af9060cc6 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryBuilder.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryBuilder.java @@ -12,15 +12,14 @@ import org.elasticsearch.common.geo.parsers.ShapeParser; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.geometry.Geometry; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.query.AbstractGeometryQueryBuilder; import org.elasticsearch.index.query.QueryRewriteContext; -import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.index.query.QueryShardException; +import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.xpack.spatial.index.mapper.ShapeQueryable; import java.io.IOException; From 384dd8632373bfec4f55b8832ca5ad104cf0333b Mon Sep 17 00:00:00 2001 From: pgomulka Date: Mon, 28 Jun 2021 13:15:24 +0200 Subject: [PATCH 3/5] yaml compat test --- .../indices.put_template/10_basic_compat.yml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 x-pack/plugin/spatial/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/indices.put_template/10_basic_compat.yml diff --git a/x-pack/plugin/spatial/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/indices.put_template/10_basic_compat.yml b/x-pack/plugin/spatial/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/indices.put_template/10_basic_compat.yml new file mode 100644 index 0000000000000..483af7c27dc23 --- /dev/null +++ b/x-pack/plugin/spatial/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/indices.put_template/10_basic_compat.yml @@ -0,0 +1,71 @@ +--- +setup: + - skip: + version: "9.0.0 - " + reason: "compatible from 8.x to 7.x" + features: + - "headers" + - "warnings" + +--- +"Test geo_shape with type": + - do: + headers: + Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" + Accept: "application/vnd.elasticsearch+json;compatible-with=7" + warnings: + - "Deprecated field [template] used, replaced by [index_patterns]" + indices.create: + index: shapes + include_type_name: true + body: + mappings: + _doc: + properties: + location: + type: geo_shape + + + - do: + headers: + Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" + Accept: "application/vnd.elasticsearch+json;compatible-with=7" + warnings: + - "Deprecated field [template] used, replaced by [index_patterns]" + index: + index: shapes + type: _doc + id: deu + body: + location: + type : "envelope" + coordinates: [[13.0, 53.0], [14.0, 52.0]] + + - do: + indices.refresh: {} + + - do: + headers: + Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" + Accept: "application/vnd.elasticsearch+json;compatible-with=7" + warnings: + - "Deprecated field [template] used, replaced by [index_patterns]" + search: + rest_total_hits_as_int: true + index: shapes + type: _doc + size: 0 + body: + query: + bool: + filter: + geo_shape: + location: + indexed_shape: + index: "shapes" + type: "_doc" + id: "deu" + path: "location" + field: location + + - match: {hits.total: 1 } From 5e3b9a7c1b57bd5bdcf0573b937b31c98fd7bf53 Mon Sep 17 00:00:00 2001 From: pgomulka Date: Mon, 28 Jun 2021 14:35:27 +0200 Subject: [PATCH 4/5] fix warning assertions --- .../10_compat_geo_shape_with_types.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename x-pack/plugin/spatial/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/{indices.put_template/10_basic_compat.yml => geo_shape/10_compat_geo_shape_with_types.yml} (100%) diff --git a/x-pack/plugin/spatial/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/indices.put_template/10_basic_compat.yml b/x-pack/plugin/spatial/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/geo_shape/10_compat_geo_shape_with_types.yml similarity index 100% rename from x-pack/plugin/spatial/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/indices.put_template/10_basic_compat.yml rename to x-pack/plugin/spatial/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/geo_shape/10_compat_geo_shape_with_types.yml From 44d7312903529e6c6ae8761cd0796ddd496dbbe6 Mon Sep 17 00:00:00 2001 From: pgomulka Date: Mon, 28 Jun 2021 14:38:22 +0200 Subject: [PATCH 5/5] test and imports --- .../spatial/index/query/ShapeQueryBuilder.java | 2 +- .../geo_shape/10_compat_geo_shape_with_types.yml | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryBuilder.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryBuilder.java index c904af9060cc6..4fea8f0607b1b 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryBuilder.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryBuilder.java @@ -18,8 +18,8 @@ import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.query.AbstractGeometryQueryBuilder; import org.elasticsearch.index.query.QueryRewriteContext; -import org.elasticsearch.index.query.QueryShardException; import org.elasticsearch.index.query.SearchExecutionContext; +import org.elasticsearch.index.query.QueryShardException; import org.elasticsearch.xpack.spatial.index.mapper.ShapeQueryable; import java.io.IOException; diff --git a/x-pack/plugin/spatial/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/geo_shape/10_compat_geo_shape_with_types.yml b/x-pack/plugin/spatial/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/geo_shape/10_compat_geo_shape_with_types.yml index 483af7c27dc23..de954080253b2 100644 --- a/x-pack/plugin/spatial/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/geo_shape/10_compat_geo_shape_with_types.yml +++ b/x-pack/plugin/spatial/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/geo_shape/10_compat_geo_shape_with_types.yml @@ -6,6 +6,7 @@ setup: features: - "headers" - "warnings" + - "allowed_warnings_regex" --- "Test geo_shape with type": @@ -13,8 +14,8 @@ setup: headers: Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" Accept: "application/vnd.elasticsearch+json;compatible-with=7" - warnings: - - "Deprecated field [template] used, replaced by [index_patterns]" + allowed_warnings_regex: + - "\\[types removal\\].*" indices.create: index: shapes include_type_name: true @@ -30,8 +31,8 @@ setup: headers: Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" Accept: "application/vnd.elasticsearch+json;compatible-with=7" - warnings: - - "Deprecated field [template] used, replaced by [index_patterns]" + allowed_warnings_regex: + - "\\[types removal\\].*" index: index: shapes type: _doc @@ -49,11 +50,10 @@ setup: Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" Accept: "application/vnd.elasticsearch+json;compatible-with=7" warnings: - - "Deprecated field [template] used, replaced by [index_patterns]" + - "[types removal] Types are deprecated in [geo_shape] queries. The type should no longer be specified in the [indexed_shape] section." search: rest_total_hits_as_int: true index: shapes - type: _doc size: 0 body: query: @@ -66,6 +66,5 @@ setup: type: "_doc" id: "deu" path: "location" - field: location - match: {hits.total: 1 }