From e3dcb7a4997566fb50ab7a25121cbe0ff667c22a Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Wed, 20 Nov 2024 17:58:56 -0500 Subject: [PATCH] More tests, fixes ExplanationDetail/value. (#685) * Added tests for PUT /{index}/_block/{block}. Signed-off-by: dblock * Added tests for PUT /{index}/_clone/{target}. Signed-off-by: dblock * Added tests for GET and POST /{index}/_explain/{id}. Signed-off-by: dblock --------- Signed-off-by: dblock --- CHANGELOG.md | 1 + spec/namespaces/_core.yaml | 2 ++ spec/schemas/_core.explain.yaml | 2 +- tests/default/indices/block.yaml | 25 +++++++++++++++ tests/default/indices/clone.yaml | 4 +-- tests/default/indices/explain.yaml | 51 ++++++++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 tests/default/indices/block.yaml create mode 100644 tests/default/indices/explain.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 880c8a949..f34eaec5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixed `/{index}/_create/{id}` returning `201` ([#669](https://github.com/opensearch-project/opensearch-api-specification/pull/669)) - Fixed `ml._common.yaml#SearchModelsResponse` and `SearchModelsHitsHit` ([#672](https://github.com/opensearch-project/opensearch-api-specification/pull/672)) - Fixed `refresh` options to allow `boolean` and `string` ([#673](https://github.com/opensearch-project/opensearch-api-specification/pull/673)) +- Fixed `value` type in `ExplanationDetail` and added `_type` to `explain@200` ([#685](https://github.com/opensearch-project/opensearch-api-specification/pull/685)) ### Changed - Changed `tasks._common:TaskInfo` and `tasks._common:TaskGroup` to be composed of a `tasks._common:TaskInfoBase` ([#683](https://github.com/opensearch-project/opensearch-api-specification/pull/683)) diff --git a/spec/namespaces/_core.yaml b/spec/namespaces/_core.yaml index 569b69b11..52a0056fd 100644 --- a/spec/namespaces/_core.yaml +++ b/spec/namespaces/_core.yaml @@ -2926,6 +2926,8 @@ components: schema: type: object properties: + _type: + $ref: '../schemas/_common.yaml#/components/schemas/Type' _index: $ref: '../schemas/_common.yaml#/components/schemas/IndexName' _id: diff --git a/spec/schemas/_core.explain.yaml b/spec/schemas/_core.explain.yaml index 5a3838a09..e7acc514b 100644 --- a/spec/schemas/_core.explain.yaml +++ b/spec/schemas/_core.explain.yaml @@ -39,7 +39,7 @@ components: items: $ref: '#/components/schemas/ExplanationDetail' value: - oneOf: + anyOf: - type: integer format: int32 - type: integer diff --git a/tests/default/indices/block.yaml b/tests/default/indices/block.yaml new file mode 100644 index 000000000..577a4ae46 --- /dev/null +++ b/tests/default/indices/block.yaml @@ -0,0 +1,25 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test limiting certain operations on a specified index. +prologues: + - path: /movies + method: PUT +epilogues: + - path: /movies + method: DELETE + status: [200, 404] +chapters: + - synopsis: Disable any write operations made to the index. + path: /{index}/_block/{block} + method: PUT + parameters: + index: movies + block: write + response: + status: 200 + payload: + shards_acknowledged: true + acknowledged: true + indices: + - name: movies + blocked: true diff --git a/tests/default/indices/clone.yaml b/tests/default/indices/clone.yaml index e2285c536..5d651b33b 100644 --- a/tests/default/indices/clone.yaml +++ b/tests/default/indices/clone.yaml @@ -41,7 +41,7 @@ chapters: - synopsis: Clone an index (wait_for_completion). version: '>= 2.7' path: /{index}/_clone/{target} - method: POST + method: PUT parameters: index: movies target: games2 @@ -51,7 +51,7 @@ chapters: - synopsis: Clone an index (cluster_manager_timeout). version: '>= 2.0' path: /{index}/_clone/{target} - method: POST + method: PUT parameters: index: movies target: games3 diff --git a/tests/default/indices/explain.yaml b/tests/default/indices/explain.yaml new file mode 100644 index 000000000..a99cc3561 --- /dev/null +++ b/tests/default/indices/explain.yaml @@ -0,0 +1,51 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test getting an explanation of how the relevance score is calculated for every result. +epilogues: + - path: /movies + method: DELETE + status: [200, 404] +prologues: + - path: /_bulk + method: POST + parameters: + refresh: true + request: + content_type: application/x-ndjson + payload: + - {create: {_index: movies, _id: movie1}} + - {director: Bennett Miller, title: The Cruise, year: 1998} + - {create: {_index: movies, _id: movie2}} + - {director: Nicolas Winding Refn, title: Drive, year: 1960} +chapters: + - synopsis: Explain the score for a match query (GET). + path: /{index}/_explain/{id} + method: GET + parameters: + index: movies + id: movie1 + request: + payload: + query: + match: + year: 1998 + response: + status: 200 + - synopsis: Explain the score for a match query (POST). + path: /{index}/_explain/{id} + method: POST + parameters: + index: movies + id: movie2 + preference: _local + routing: primary + _source: true + _source_excludes: title + _source_includes: director + request: + payload: + query: + match: + title: Drive + response: + status: 200