From fec92447266d548834cc11bdb846e94786fa3c35 Mon Sep 17 00:00:00 2001 From: Fanit Kolchina Date: Tue, 16 Jul 2024 12:58:30 -0400 Subject: [PATCH 1/5] Add geodistance query test Signed-off-by: Fanit Kolchina --- spec/schemas/_common.query_dsl.yaml | 8 ++++ tests/_core/geodistance_query.yaml | 60 +++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/_core/geodistance_query.yaml diff --git a/spec/schemas/_common.query_dsl.yaml b/spec/schemas/_common.query_dsl.yaml index 7c4490df8..ca018574a 100644 --- a/spec/schemas/_common.query_dsl.yaml +++ b/spec/schemas/_common.query_dsl.yaml @@ -625,8 +625,16 @@ components: $ref: '_common.yaml#/components/schemas/GeoDistanceType' validation_method: $ref: '#/components/schemas/GeoValidationMethod' + ignore_unmapped: + description: |- + Set to `true` to ignore an unmapped field and not match any documents for this query. + Set to `false` to throw an exception if the field is not mapped. + type: boolean + field: + type: object required: - distance + - field GeoPolygonQuery: allOf: - $ref: '#/components/schemas/QueryBase' diff --git a/tests/_core/geodistance_query.yaml b/tests/_core/geodistance_query.yaml new file mode 100644 index 000000000..f3e6aa5b5 --- /dev/null +++ b/tests/_core/geodistance_query.yaml @@ -0,0 +1,60 @@ +$schema: ../../json_schemas/test_story.schema.yaml + +description: Test search endpoint with geodistance query. +prologues: + - path: /testindex1 + method: PUT + request_body: + payload: + mappings: + properties: + field: + type: geo_point + - path: /testindex1/_doc/1 + method: POST + parameters: + refresh: true + request_body: + payload: + field: + lat: 74.00 + lon: 40.71 + status: [201] +epilogues: + - path: /testindex1 + method: DELETE + status: [200, 404] +chapters: + - synopsis: Search for documents whose point objects are within the specified distance from the specified point. + path: /{index}/_search + parameters: + index: testindex1 + method: GET + request_body: + payload: + query: + geo_distance: + distance: "50mi" + distance_type: "arc" + validation_method: "strict" + ignore_unmapped: true + field: + lat: 73.5 + lon: 40.5 + response: + status: 200 + payload: + timed_out: false + hits: + total: + value: 1 + relation: eq + max_score: 1 + hits: + - _index: testindex1 + _score: 1 + _source: + field: + lat: 74 + lon: 40.71 + From e6929fefce27a13ba1ac8ab781c087bdc0e8c3e1 Mon Sep 17 00:00:00 2001 From: Fanit Kolchina Date: Tue, 16 Jul 2024 13:21:43 -0400 Subject: [PATCH 2/5] Correct linting errors Signed-off-by: Fanit Kolchina --- spec/schemas/_common.query_dsl.yaml | 2 +- tests/_core/geodistance_query.yaml | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/schemas/_common.query_dsl.yaml b/spec/schemas/_common.query_dsl.yaml index ca018574a..bb8b29ade 100644 --- a/spec/schemas/_common.query_dsl.yaml +++ b/spec/schemas/_common.query_dsl.yaml @@ -631,7 +631,7 @@ components: Set to `false` to throw an exception if the field is not mapped. type: boolean field: - type: object + type: object required: - distance - field diff --git a/tests/_core/geodistance_query.yaml b/tests/_core/geodistance_query.yaml index f3e6aa5b5..1ed0b30a8 100644 --- a/tests/_core/geodistance_query.yaml +++ b/tests/_core/geodistance_query.yaml @@ -1,8 +1,8 @@ $schema: ../../json_schemas/test_story.schema.yaml -description: Test search endpoint with geodistance query. +description: Test search endpoint with geo_distance query. prologues: - - path: /testindex1 + - path: /test_index method: PUT request_body: payload: @@ -10,33 +10,33 @@ prologues: properties: field: type: geo_point - - path: /testindex1/_doc/1 - method: POST + - path: /test_index/_doc/1 + method: POS parameters: refresh: true request_body: payload: field: - lat: 74.00 + lat: 74 lon: 40.71 status: [201] epilogues: - - path: /testindex1 + - path: /test_index method: DELETE status: [200, 404] chapters: - synopsis: Search for documents whose point objects are within the specified distance from the specified point. path: /{index}/_search parameters: - index: testindex1 + index: test_index method: GET request_body: payload: query: geo_distance: - distance: "50mi" - distance_type: "arc" - validation_method: "strict" + distance: 50mi + distance_type: arc + validation_method: strict ignore_unmapped: true field: lat: 73.5 @@ -51,7 +51,7 @@ chapters: relation: eq max_score: 1 hits: - - _index: testindex1 + - _index: test_index _score: 1 _source: field: From bdcd7cf9ae1354f819ec1149c56f98ca3e7761e7 Mon Sep 17 00:00:00 2001 From: Fanit Kolchina Date: Tue, 16 Jul 2024 13:51:42 -0400 Subject: [PATCH 3/5] Correct method name Signed-off-by: Fanit Kolchina --- tests/_core/geodistance_query.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/_core/geodistance_query.yaml b/tests/_core/geodistance_query.yaml index 1ed0b30a8..95119ca9d 100644 --- a/tests/_core/geodistance_query.yaml +++ b/tests/_core/geodistance_query.yaml @@ -11,7 +11,7 @@ prologues: field: type: geo_point - path: /test_index/_doc/1 - method: POS + method: POST parameters: refresh: true request_body: From dcbe9408cf014cee5aa00f3f874c88f088d1454d Mon Sep 17 00:00:00 2001 From: Fanit Kolchina Date: Tue, 16 Jul 2024 16:19:01 -0400 Subject: [PATCH 4/5] Addressed review comments Signed-off-by: Fanit Kolchina --- CHANGELOG.md | 1 + spec/schemas/_common.query_dsl.yaml | 1 + tests/_core/search.yaml | 151 ------------------ .../search/cancel_after_time_interval.yaml | 28 ++++ .../geo_distance.yaml} | 12 +- tests/_core/search/match.yaml | 56 +++++++ tests/_core/search/multi_match.yaml | 45 ++++++ tests/_core/search/phase_took.yaml | 28 ++++ tests/_core/search/seq_no_primary_term.yaml | 41 +++++ tests/_core/search/size.yaml | 64 ++++++++ 10 files changed, 270 insertions(+), 157 deletions(-) delete mode 100644 tests/_core/search.yaml create mode 100644 tests/_core/search/cancel_after_time_interval.yaml rename tests/_core/{geodistance_query.yaml => search/geo_distance.yaml} (86%) create mode 100644 tests/_core/search/match.yaml create mode 100644 tests/_core/search/multi_match.yaml create mode 100644 tests/_core/search/phase_took.yaml create mode 100644 tests/_core/search/seq_no_primary_term.yaml create mode 100644 tests/_core/search/size.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index d4a709673..09a812fc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added `file` to `/_cache/clear` and `/{index}/_cache/clear` ([#396](https://github.com/opensearch-project/opensearch-api-specification/pull/396)) - Added a workflow to run tests against the next version of OpenSearch ([#409](https://github.com/opensearch-project/opensearch-api-specification/pull/409)) - Added support for skipping tests using semver range ([#410](https://github.com/opensearch-project/opensearch-api-specification/pull/410)) +- Added `ignore_unmapped` to `GeoDistanceQuery` ([#427](https://github.com/opensearch-project/opensearch-api-specification/pull/427)) ### Changed diff --git a/spec/schemas/_common.query_dsl.yaml b/spec/schemas/_common.query_dsl.yaml index bb8b29ade..7d53d8355 100644 --- a/spec/schemas/_common.query_dsl.yaml +++ b/spec/schemas/_common.query_dsl.yaml @@ -630,6 +630,7 @@ components: Set to `true` to ignore an unmapped field and not match any documents for this query. Set to `false` to throw an exception if the field is not mapped. type: boolean + default: false field: type: object required: diff --git a/tests/_core/search.yaml b/tests/_core/search.yaml deleted file mode 100644 index cfc9ad340..000000000 --- a/tests/_core/search.yaml +++ /dev/null @@ -1,151 +0,0 @@ -$schema: ../../json_schemas/test_story.schema.yaml - -description: Test search endpoint. -prologues: - - path: /movies/_doc - method: POST - parameters: - refresh: true - request_body: - payload: - director: Bennett Miller - title: Moneyball - year: 2011 - status: [201] -epilogues: - - path: /movies - method: DELETE - status: [200, 404] -chapters: - - synopsis: Search with size=0. - path: /{index}/_search - parameters: - index: movies - method: POST - request_body: - payload: - size: 0 - response: - status: 200 - payload: - timed_out: false - hits: - total: - value: 1 - relation: eq - max_score: null - hits: [] - - synopsis: Search with size=1. - path: /{index}/_search - parameters: - index: movies - method: POST - request_body: - payload: - size: 1 - query: - match_all: {} - response: - status: 200 - payload: - timed_out: false - hits: - total: - value: 1 - relation: eq - max_score: 1 - hits: - - _index: movies - _score: 1 - _source: - director: Bennett Miller - title: Moneyball - year: 2011 - - synopsis: Search with a match query object. - path: /{index}/_search - parameters: - index: movies - method: POST - request_body: - payload: - size: 1 - query: - match: - director: - query: Bennett Miller - - synopsis: Search with a match query field. - path: /{index}/_search - parameters: - index: movies - method: POST - request_body: - payload: - size: 1 - query: - match: - director: Bennett Miller - - synopsis: Search with multi_match query. - path: /{index}/_search - parameters: - index: movies - method: POST - request_body: - payload: - size: 1 - query: - multi_match: - query: miller - fields: ["title^2", "director"] - response: - status: 200 - payload: - timed_out: false - hits: - total: - value: 1 - relation: eq - hits: - - _index: movies - _source: - director: Bennett Miller - title: Moneyball - year: 2011 - - synopsis: Search with cancel_after_time_interval. - path: /{index}/_search - parameters: - index: movies - cancel_after_time_interval: 10s - method: POST - response: - status: 200 - - synopsis: Search with phase_took. - version: '>= 2.12' - path: /{index}/_search - parameters: - index: movies - phase_took: true - method: POST - response: - status: 200 - - synopsis: Search with seq_no_primary_term. - path: /{index}/_search - parameters: - index: movies - seq_no_primary_term: true - method: POST - response: - status: 200 - payload: - timed_out: false - hits: - total: - value: 1 - relation: eq - hits: - - _index: movies - _source: - director: Bennett Miller - title: Moneyball - year: 2011 - _seq_no: 0 - _primary_term: 1 diff --git a/tests/_core/search/cancel_after_time_interval.yaml b/tests/_core/search/cancel_after_time_interval.yaml new file mode 100644 index 000000000..012a7972e --- /dev/null +++ b/tests/_core/search/cancel_after_time_interval.yaml @@ -0,0 +1,28 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test search endpoint with cancel_after_time_interval. +prologues: + - path: /movies/_doc + method: POST + parameters: + refresh: true + request_body: + payload: + director: Bennett Miller + title: Moneyball + year: 2011 + status: [201] +epilogues: + - path: /movies + method: DELETE + status: [200, 404] +chapters: + - synopsis: Search with cancel_after_time_interval. + path: /{index}/_search + parameters: + index: movies + cancel_after_time_interval: 10s + method: POST + response: + status: 200 + diff --git a/tests/_core/geodistance_query.yaml b/tests/_core/search/geo_distance.yaml similarity index 86% rename from tests/_core/geodistance_query.yaml rename to tests/_core/search/geo_distance.yaml index 95119ca9d..8ce5712d0 100644 --- a/tests/_core/geodistance_query.yaml +++ b/tests/_core/search/geo_distance.yaml @@ -1,8 +1,8 @@ -$schema: ../../json_schemas/test_story.schema.yaml +$schema: ../../../json_schemas/test_story.schema.yaml description: Test search endpoint with geo_distance query. prologues: - - path: /test_index + - path: /map method: PUT request_body: payload: @@ -10,7 +10,7 @@ prologues: properties: field: type: geo_point - - path: /test_index/_doc/1 + - path: /map/_doc/1 method: POST parameters: refresh: true @@ -21,14 +21,14 @@ prologues: lon: 40.71 status: [201] epilogues: - - path: /test_index + - path: /map method: DELETE status: [200, 404] chapters: - synopsis: Search for documents whose point objects are within the specified distance from the specified point. path: /{index}/_search parameters: - index: test_index + index: map method: GET request_body: payload: @@ -51,7 +51,7 @@ chapters: relation: eq max_score: 1 hits: - - _index: test_index + - _index: map _score: 1 _source: field: diff --git a/tests/_core/search/match.yaml b/tests/_core/search/match.yaml new file mode 100644 index 000000000..78afe3ddf --- /dev/null +++ b/tests/_core/search/match.yaml @@ -0,0 +1,56 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test search endpoint with match query. +prologues: + - path: /movies/_doc + method: POST + parameters: + refresh: true + request_body: + payload: + director: Bennett Miller + title: Moneyball + year: 2011 + status: [201] +epilogues: + - path: /movies + method: DELETE + status: [200, 404] +chapters: + - synopsis: Search with a match query object. + path: /{index}/_search + parameters: + index: movies + method: POST + request_body: + payload: + size: 1 + query: + match: + director: + query: Bennett Miller + - synopsis: Search with a match query field. + path: /{index}/_search + parameters: + index: movies + method: POST + request_body: + payload: + size: 1 + query: + match: + director: Bennett Miller + response: + status: 200 + payload: + timed_out: false + hits: + total: + value: 1 + relation: eq + hits: + - _index: movies + _source: + director: Bennett Miller + title: Moneyball + year: 2011 diff --git a/tests/_core/search/multi_match.yaml b/tests/_core/search/multi_match.yaml new file mode 100644 index 000000000..0864954ef --- /dev/null +++ b/tests/_core/search/multi_match.yaml @@ -0,0 +1,45 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test search endpoint with multi_match query. +prologues: + - path: /movies/_doc + method: POST + parameters: + refresh: true + request_body: + payload: + director: Bennett Miller + title: Moneyball + year: 2011 + status: [201] +epilogues: + - path: /movies + method: DELETE + status: [200, 404] +chapters: + - synopsis: Search with multi_match query. + path: /{index}/_search + parameters: + index: movies + method: POST + request_body: + payload: + size: 1 + query: + multi_match: + query: miller + fields: ["title^2", "director"] + response: + status: 200 + payload: + timed_out: false + hits: + total: + value: 1 + relation: eq + hits: + - _index: movies + _source: + director: Bennett Miller + title: Moneyball + year: 2011 diff --git a/tests/_core/search/phase_took.yaml b/tests/_core/search/phase_took.yaml new file mode 100644 index 000000000..846d0fe86 --- /dev/null +++ b/tests/_core/search/phase_took.yaml @@ -0,0 +1,28 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test search endpoint with phase_took. +prologues: + - path: /movies/_doc + method: POST + parameters: + refresh: true + request_body: + payload: + director: Bennett Miller + title: Moneyball + year: 2011 + status: [201] +epilogues: + - path: /movies + method: DELETE + status: [200, 404] +chapters: + - synopsis: Search with phase_took. + version: '>= 2.12' + path: /{index}/_search + parameters: + index: movies + phase_took: true + method: POST + response: + status: 200 diff --git a/tests/_core/search/seq_no_primary_term.yaml b/tests/_core/search/seq_no_primary_term.yaml new file mode 100644 index 000000000..07b0d5834 --- /dev/null +++ b/tests/_core/search/seq_no_primary_term.yaml @@ -0,0 +1,41 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test search endpoint with seq_no_primary_term. +prologues: + - path: /movies/_doc + method: POST + parameters: + refresh: true + request_body: + payload: + director: Bennett Miller + title: Moneyball + year: 2011 + status: [201] +epilogues: + - path: /movies + method: DELETE + status: [200, 404] +chapters: + - synopsis: Search with seq_no_primary_term. + path: /{index}/_search + parameters: + index: movies + seq_no_primary_term: true + method: POST + response: + status: 200 + payload: + timed_out: false + hits: + total: + value: 1 + relation: eq + hits: + - _index: movies + _source: + director: Bennett Miller + title: Moneyball + year: 2011 + _seq_no: 0 + _primary_term: 1 diff --git a/tests/_core/search/size.yaml b/tests/_core/search/size.yaml new file mode 100644 index 000000000..154f34638 --- /dev/null +++ b/tests/_core/search/size.yaml @@ -0,0 +1,64 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test search endpoint with size. +prologues: + - path: /movies/_doc + method: POST + parameters: + refresh: true + request_body: + payload: + director: Bennett Miller + title: Moneyball + year: 2011 + status: [201] +epilogues: + - path: /movies + method: DELETE + status: [200, 404] +chapters: + - synopsis: Search with size=0. + path: /{index}/_search + parameters: + index: movies + method: POST + request_body: + payload: + size: 0 + response: + status: 200 + payload: + timed_out: false + hits: + total: + value: 1 + relation: eq + max_score: null + hits: [] + - synopsis: Search with size=1. + path: /{index}/_search + parameters: + index: movies + method: POST + request_body: + payload: + size: 1 + query: + match_all: {} + response: + status: 200 + payload: + timed_out: false + hits: + total: + value: 1 + relation: eq + max_score: 1 + hits: + - _index: movies + _score: 1 + _source: + director: Bennett Miller + title: Moneyball + year: 2011 + \ No newline at end of file From 2d59b95ed431632065891096a5c1e5d9db344fbc Mon Sep 17 00:00:00 2001 From: Fanit Kolchina Date: Wed, 17 Jul 2024 09:10:19 -0400 Subject: [PATCH 5/5] Remove trailing line Signed-off-by: Fanit Kolchina --- tests/_core/search/size.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/_core/search/size.yaml b/tests/_core/search/size.yaml index 154f34638..6ea5bb3ec 100644 --- a/tests/_core/search/size.yaml +++ b/tests/_core/search/size.yaml @@ -60,5 +60,4 @@ chapters: _source: director: Bennett Miller title: Moneyball - year: 2011 - \ No newline at end of file + year: 2011 \ No newline at end of file