From 51cb05aa996803e4527388723222ba381923f842 Mon Sep 17 00:00:00 2001 From: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Date: Thu, 18 Jul 2024 08:10:17 -0400 Subject: [PATCH] Add geodistance query test (#427) * Add geodistance query test Signed-off-by: Fanit Kolchina * Correct linting errors Signed-off-by: Fanit Kolchina * Correct method name Signed-off-by: Fanit Kolchina * Fixed merge conflicts Signed-off-by: Fanit Kolchina --------- Signed-off-by: Fanit Kolchina Signed-off-by: Daniel (dB.) Doubrovkine Co-authored-by: Daniel (dB.) Doubrovkine --- CHANGELOG.md | 1 + spec/schemas/_common.query_dsl.yaml | 9 ++ tests/_core/search.yaml | 151 ------------------ .../search/cancel_after_time_interval.yaml | 28 ++++ tests/_core/search/geo_distance.yaml | 60 +++++++ 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, 332 insertions(+), 151 deletions(-) delete mode 100644 tests/_core/search.yaml create mode 100644 tests/_core/search/cancel_after_time_interval.yaml create mode 100644 tests/_core/search/geo_distance.yaml 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 e3a35775..77712942 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added missing metrics options to `/_nodes/stats` ([#422](https://github.com/opensearch-project/opensearch-api-specification/pull/422)) - Added tests against OpenSearch 1.3 ([#424](https://github.com/opensearch-project/opensearch-api-specification/pull/424)) - Added `is_hidden` to `/{index}/_alias/{name}` and `/{index}/_aliases/{name}` ([#429](https://github.com/opensearch-project/opensearch-api-specification/pull/429)) +- 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 7ad1e78f..3fab6cef 100644 --- a/spec/schemas/_common.query_dsl.yaml +++ b/spec/schemas/_common.query_dsl.yaml @@ -625,8 +625,17 @@ 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 + default: false + field: + type: object required: - distance + - field GeoPolygonQuery: allOf: - $ref: '#/components/schemas/QueryBase' diff --git a/tests/_core/search.yaml b/tests/_core/search.yaml deleted file mode 100644 index a1760ee5..00000000 --- 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: [director, title^2] - 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 00000000..012a7972 --- /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/search/geo_distance.yaml b/tests/_core/search/geo_distance.yaml new file mode 100644 index 00000000..8ce5712d --- /dev/null +++ b/tests/_core/search/geo_distance.yaml @@ -0,0 +1,60 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test search endpoint with geo_distance query. +prologues: + - path: /map + method: PUT + request_body: + payload: + mappings: + properties: + field: + type: geo_point + - path: /map/_doc/1 + method: POST + parameters: + refresh: true + request_body: + payload: + field: + lat: 74 + lon: 40.71 + status: [201] +epilogues: + - 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: map + 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: map + _score: 1 + _source: + field: + lat: 74 + lon: 40.71 + diff --git a/tests/_core/search/match.yaml b/tests/_core/search/match.yaml new file mode 100644 index 00000000..78afe3dd --- /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 00000000..4ea41f74 --- /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: [director, title^2] + 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 00000000..846d0fe8 --- /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 00000000..07b0d583 --- /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 00000000..154f3463 --- /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