From 5cd57c41ea790b1d4654401828e225afbf10cb58 Mon Sep 17 00:00:00 2001 From: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Date: Mon, 9 Sep 2024 10:56:53 -0400 Subject: [PATCH] Update spec and add tests for xy, geo shape, and geo bounding box query (#531) * Adds xy shape query spec and test Signed-off-by: Fanit Kolchina * Update spec and add tests for geo bounding box and geo shape Signed-off-by: Fanit Kolchina * Address linter errors Signed-off-by: Fanit Kolchina * Add version added to xy field types and query Signed-off-by: Fanit Kolchina * Fix lint errors Signed-off-by: Fanit Kolchina * Remove ShapeQuery from spec and make list ordered Signed-off-by: Fanit Kolchina * Extract objects into refs Signed-off-by: Fanit Kolchina * Extract last object and add changelog entry Signed-off-by: Fanit Kolchina * Implement code review comments Signed-off-by: Fanit Kolchina * Fix lint errors Signed-off-by: Fanit Kolchina * Apply suggestions from code review Co-authored-by: Daniel (dB.) Doubrovkine Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> --------- Signed-off-by: Fanit Kolchina Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Co-authored-by: Daniel (dB.) Doubrovkine --- CHANGELOG.md | 3 + spec/schemas/_common.mapping.yaml | 20 +++-- spec/schemas/_common.query_dsl.yaml | 74 ++++++++++++++----- spec/schemas/_common.yaml | 26 +++++++ .../_core/search/query/geo_bounding_box.yaml | 60 +++++++++++++++ .../_core/search/query/geo_shape_point.yaml | 52 +++++++++++++ .../_core/search/query/geo_shape_shape.yaml | 58 +++++++++++++++ .../_core/search/query/xy_shape_point.yaml | 53 +++++++++++++ .../_core/search/query/xy_shape_shape.yaml | 58 +++++++++++++++ 9 files changed, 380 insertions(+), 24 deletions(-) create mode 100644 tests/default/_core/search/query/geo_bounding_box.yaml create mode 100644 tests/default/_core/search/query/geo_shape_point.yaml create mode 100644 tests/default/_core/search/query/geo_shape_shape.yaml create mode 100644 tests/default/_core/search/query/xy_shape_point.yaml create mode 100644 tests/default/_core/search/query/xy_shape_shape.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index a961108f6..942d32ecf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -91,6 +91,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added request and response schemas for `/_cluster/routing/awareness/{attribute}/weights` ([#524](https://github.com/opensearch-project/opensearch-api-specification/pull/524)) - Added request and response schemas for `/_cluster/decommission/awareness` ([#524](https://github.com/opensearch-project/opensearch-api-specification/pull/524)) - Added `Bytes` component of type number ([#552](https://github.com/opensearch-project/opensearch-api-specification/pull/552)) +- Added `xy_shape` query ([#531](https://github.com/opensearch-project/opensearch-api-specification/pull/531)) ### Changed @@ -114,6 +115,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Removed - Removed the ability to skip an individual spec test ([#358](https://github.com/opensearch-project/opensearch-api-specification/pull/358)) +- Removed `shape` query ([#531](https://github.com/opensearch-project/opensearch-api-specification/pull/531)) ### Fixed @@ -145,6 +147,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixed content-type for `/hot_threads` ([#543](https://github.com/opensearch-project/opensearch-api-specification/pull/543)) - Fixed `/_cluster/settings` returning flat results ([#545](https://github.com/opensearch-project/opensearch-api-specification/pull/545)) - Fixed missing fields in `_cat` API ([#551](https://github.com/opensearch-project/opensearch-api-specification/pull/551)) +- Fixed `geo_bounding_box` and `geo_shape` queries ([#531](https://github.com/opensearch-project/opensearch-api-specification/pull/531)) ### Security diff --git a/spec/schemas/_common.mapping.yaml b/spec/schemas/_common.mapping.yaml index ef7a31a31..14edfcebe 100644 --- a/spec/schemas/_common.mapping.yaml +++ b/spec/schemas/_common.mapping.yaml @@ -191,8 +191,8 @@ components: - $ref: '#/components/schemas/TokenCountProperty' - $ref: '#/components/schemas/GeoPointProperty' - $ref: '#/components/schemas/GeoShapeProperty' - - $ref: '#/components/schemas/PointProperty' - - $ref: '#/components/schemas/ShapeProperty' + - $ref: '#/components/schemas/XyPointProperty' + - $ref: '#/components/schemas/XyShapeProperty' - $ref: '#/components/schemas/ByteNumberProperty' - $ref: '#/components/schemas/DoubleNumberProperty' - $ref: '#/components/schemas/FloatNumberProperty' @@ -913,6 +913,10 @@ components: $ref: '#/components/schemas/GeoOrientation' strategy: $ref: '#/components/schemas/GeoStrategy' + deprecated: true + distance_error_pct: + type: number + deprecated: true type: type: string enum: @@ -929,7 +933,8 @@ components: enum: - recursive - term - PointProperty: + XyPointProperty: + # x-version-added: 2.4 allOf: - $ref: '#/components/schemas/DocValuesPropertyBase' - type: object @@ -939,14 +944,15 @@ components: ignore_z_value: type: boolean null_value: - type: string + $ref: '_common.yaml#/components/schemas/XyLocation' type: type: string enum: - - point + - xy_point required: - type - ShapeProperty: + XyShapeProperty: + # x-version-added: 2.4 allOf: - $ref: '#/components/schemas/DocValuesPropertyBase' - type: object @@ -962,7 +968,7 @@ components: type: type: string enum: - - shape + - xy_shape required: - type ByteNumberProperty: diff --git a/spec/schemas/_common.query_dsl.yaml b/spec/schemas/_common.query_dsl.yaml index bb2c44c7d..7bb1b4a29 100644 --- a/spec/schemas/_common.query_dsl.yaml +++ b/spec/schemas/_common.query_dsl.yaml @@ -153,8 +153,6 @@ components: $ref: '#/components/schemas/ScriptQuery' script_score: $ref: '#/components/schemas/ScriptScoreQuery' - shape: - $ref: '#/components/schemas/ShapeQuery' simple_query_string: $ref: '#/components/schemas/SimpleQueryStringQuery' span_containing: @@ -209,6 +207,8 @@ components: $ref: '#/components/schemas/TextExpansionQuery' minProperties: 1 maxProperties: 1 + type: + $ref: '#/components/schemas/TypeQuery' weighted_tokens: description: Supports returning text_expansion query results by sending in precomputed tokens with the query. type: object @@ -225,8 +225,8 @@ components: maxProperties: 1 wrapper: $ref: '#/components/schemas/WrapperQuery' - type: - $ref: '#/components/schemas/TypeQuery' + xy_shape: + $ref: '#/components/schemas/XyShapeQuery' minProperties: 1 maxProperties: 1 BoolQuery: @@ -629,6 +629,9 @@ components: $ref: '#/components/schemas/GeoValidationMethod' ignore_unmapped: $ref: '#/components/schemas/IgnoreUnmapped' + additionalProperties: + $ref: '_common.yaml#/components/schemas/GeoBounds' + minProperties: 1 GeoExecution: type: string enum: @@ -667,6 +670,22 @@ components: $ref: '#/components/schemas/GeoValidationMethod' ignore_unmapped: $ref: '#/components/schemas/IgnoreUnmapped' + GeoShape: + type: object + properties: + type: + type: string + coordinates: + type: array + GeoShapeField: + type: object + properties: + shape: + $ref: '#/components/schemas/GeoShape' + relation: + $ref: '_common.yaml#/components/schemas/GeoShapeRelation' + required: + - shape GeoShapeQuery: allOf: - $ref: '#/components/schemas/QueryBase' @@ -674,6 +693,9 @@ components: properties: ignore_unmapped: $ref: '#/components/schemas/IgnoreUnmapped' + additionalProperties: + $ref: '#/components/schemas/GeoShapeField' + minProperties: 1 HasChildQuery: allOf: - $ref: '#/components/schemas/QueryBase' @@ -1626,13 +1648,6 @@ components: required: - query - script - ShapeQuery: - allOf: - - $ref: '#/components/schemas/QueryBase' - - type: object - properties: - ignore_unmapped: - $ref: '#/components/schemas/IgnoreUnmapped' SimpleQueryStringQuery: allOf: - $ref: '#/components/schemas/QueryBase' @@ -1918,6 +1933,15 @@ components: only_score_pruned_tokens: description: Whether to only score pruned tokens, vs only scoring kept tokens. type: boolean + TypeQuery: + allOf: + - $ref: '#/components/schemas/QueryBase' + - type: object + properties: + value: + type: string + required: + - value WeightedTokensQuery: allOf: - $ref: '#/components/schemas/QueryBase' @@ -1960,12 +1984,28 @@ components: type: string required: - query - TypeQuery: + XyShape: + type: object + properties: + type: + type: string + coordinates: + type: array + XyShapeField: + type: object + properties: + shape: + $ref: '#/components/schemas/XyShape' + relation: + $ref: '_common.yaml#/components/schemas/GeoShapeRelation' + required: + - shape + XyShapeQuery: + x-version-added: 2.4 allOf: - $ref: '#/components/schemas/QueryBase' - type: object - properties: - value: - type: string - required: - - value + additionalProperties: + $ref: '#/components/schemas/XyShapeField' + minProperties: 1 + maxProperties: 1 \ No newline at end of file diff --git a/spec/schemas/_common.yaml b/spec/schemas/_common.yaml index 7e55ff907..845204b3a 100644 --- a/spec/schemas/_common.yaml +++ b/spec/schemas/_common.yaml @@ -133,6 +133,32 @@ components: type: string required: - wkt + XyLocation: + x-version-added: 2.4 + description: |- + A two-dimensional Cartesian point specified by x and y coordinates. It can be represented in various ways: + - as a `{x, y}` object + - as a `[x, y]` array + - as a string in `"x, y"` or WKT point formats. + oneOf: + - $ref: '#/components/schemas/XyCartesianCoordinates' + - type: array + items: + type: number + - type: string + XyCartesianCoordinates: + x-version-added: '2.4' + type: object + properties: + x: + description: The x coordinate. + type: number + y: + description: The y coordinate. + type: number + required: + - x + - y EpochTimeUnitMillis: allOf: - $ref: '#/components/schemas/UnitMillis' diff --git a/tests/default/_core/search/query/geo_bounding_box.yaml b/tests/default/_core/search/query/geo_bounding_box.yaml new file mode 100644 index 000000000..1bdc7f605 --- /dev/null +++ b/tests/default/_core/search/query/geo_bounding_box.yaml @@ -0,0 +1,60 @@ +$schema: ../../../../../json_schemas/test_story.schema.yaml + +description: Test search endpoint with geo_bounding_box query. +prologues: + - path: /point_index + method: PUT + request: + payload: + mappings: + properties: + field: + type: geo_point + - path: /point_index/_doc/1 + method: POST + parameters: + refresh: true + request: + payload: + field: + lat: 74 + lon: 40 + status: [201] +epilogues: + - path: /point_index + method: DELETE + status: [200, 404] +chapters: + - synopsis: Search point_index for documents whose point objects are within the specified bounding box. + path: /{index}/_search + parameters: + index: point_index + method: GET + request: + payload: + query: + geo_bounding_box: + field: + top: 75 + left: 28 + bottom: 73 + right: 41 + validation_method: strict + type: memory + ignore_unmapped: false + response: + status: 200 + payload: + timed_out: false + hits: + total: + value: 1 + relation: eq + max_score: 1 + hits: + - _index: point_index + _score: 1 + _source: + field: + lat: 74 + lon: 40 \ No newline at end of file diff --git a/tests/default/_core/search/query/geo_shape_point.yaml b/tests/default/_core/search/query/geo_shape_point.yaml new file mode 100644 index 000000000..d55748f95 --- /dev/null +++ b/tests/default/_core/search/query/geo_shape_point.yaml @@ -0,0 +1,52 @@ +$schema: ../../../../../json_schemas/test_story.schema.yaml + +description: Test search endpoint with geo_shape query. +prologues: + - path: /cinemas + method: PUT + request: + payload: + mappings: + properties: + location: + type: geo_point + - path: /cinemas/_doc/1 + method: POST + parameters: + refresh: true + request: + payload: + location: [0.5, 3] + status: [201] +epilogues: + - path: /cinemas + method: DELETE + status: [200, 404] +chapters: + - synopsis: Search cinemas for documents whose point objects are within the specified envelope. + path: /{index}/_search + parameters: + index: cinemas + method: GET + request: + payload: + query: + geo_shape: + location: + shape: + type: envelope + coordinates: [[0, 6], [1, 2]] + response: + status: 200 + payload: + timed_out: false + hits: + total: + value: 1 + relation: eq + max_score: 0 + hits: + - _index: cinemas + _score: 0 + _source: + location: [0.5, 3] \ No newline at end of file diff --git a/tests/default/_core/search/query/geo_shape_shape.yaml b/tests/default/_core/search/query/geo_shape_shape.yaml new file mode 100644 index 000000000..224805a60 --- /dev/null +++ b/tests/default/_core/search/query/geo_shape_shape.yaml @@ -0,0 +1,58 @@ +$schema: ../../../../../json_schemas/test_story.schema.yaml + +description: Test search endpoint with geo_shape query. +prologues: + - path: /cinemas + method: PUT + request: + payload: + mappings: + properties: + location: + type: geo_shape + - path: /cinemas/_doc/1 + method: POST + parameters: + refresh: true + request: + payload: + location: + type: point + coordinates: [0.5, 3] + status: [201] +epilogues: + - path: /cinemas + method: DELETE + status: [200, 404] +chapters: + - synopsis: Search cinemas for documents whose point objects are within the specified envelope. + path: /{index}/_search + parameters: + index: cinemas + method: GET + request: + payload: + query: + geo_shape: + location: + shape: + type: envelope + coordinates: [[0, 6], [1, 2]] + relation: within + ignore_unmapped: true + response: + status: 200 + payload: + timed_out: false + hits: + total: + value: 1 + relation: eq + max_score: 0 + hits: + - _index: cinemas + _score: 0 + _source: + location: + type: point + coordinates: [0.5, 3] diff --git a/tests/default/_core/search/query/xy_shape_point.yaml b/tests/default/_core/search/query/xy_shape_point.yaml new file mode 100644 index 000000000..2e3a12995 --- /dev/null +++ b/tests/default/_core/search/query/xy_shape_point.yaml @@ -0,0 +1,53 @@ +$schema: ../../../../../json_schemas/test_story.schema.yaml + +description: Test search endpoint with xy query. +version: '>= 2.4' +prologues: + - path: /point_index + method: PUT + request: + payload: + mappings: + properties: + field: + type: xy_point + - path: /point_index/_doc/1 + method: POST + parameters: + refresh: true + request: + payload: + field: [0.5, 3] + status: [201] +epilogues: + - path: /point_index + method: DELETE + status: [200, 404] +chapters: + - synopsis: Search point_index for documents whose point objects are within the specified envelope. + path: /{index}/_search + parameters: + index: point_index + method: GET + request: + payload: + query: + xy_shape: + field: + shape: + type: envelope + coordinates: [[0, 6], [1, 2]] + response: + status: 200 + payload: + timed_out: false + hits: + total: + value: 1 + relation: eq + max_score: 0 + hits: + - _index: point_index + _score: 0 + _source: + field: [0.5, 3] \ No newline at end of file diff --git a/tests/default/_core/search/query/xy_shape_shape.yaml b/tests/default/_core/search/query/xy_shape_shape.yaml new file mode 100644 index 000000000..74f87eba0 --- /dev/null +++ b/tests/default/_core/search/query/xy_shape_shape.yaml @@ -0,0 +1,58 @@ +$schema: ../../../../../json_schemas/test_story.schema.yaml + +description: Test search endpoint with xy query. +version: '>= 2.4' +prologues: + - path: /shape_index + method: PUT + request: + payload: + mappings: + properties: + field: + type: xy_shape + - path: /shape_index/_doc/1 + method: POST + parameters: + refresh: true + request: + payload: + field: + type: point + coordinates: [0.5, 3] + status: [201] +epilogues: + - path: /shape_index + method: DELETE + status: [200, 404] +chapters: + - synopsis: Search shape_index for documents whose point objects are within the specified envelope. + path: /{index}/_search + parameters: + index: shape_index + method: GET + request: + payload: + query: + xy_shape: + field: + shape: + type: envelope + coordinates: [[0, 6], [1, 2]] + relation: within + response: + status: 200 + payload: + timed_out: false + hits: + total: + value: 1 + relation: eq + max_score: 0 + hits: + - _index: shape_index + _score: 0 + _source: + field: + type: point + coordinates: [0.5, 3] \ No newline at end of file