From 4226d83a23bd85bf59d9a17e3899e370d47cec3e Mon Sep 17 00:00:00 2001 From: Niyazbek Torekeldi <78027392+Tokesh@users.noreply.github.com> Date: Tue, 17 Dec 2024 23:04:08 +0500 Subject: [PATCH] Msearch template API tests (#735) * added msearch template tests Signed-off-by: Tokesh * lint fix Signed-off-by: Tokesh * added core msearch template tests Signed-off-by: Tokesh * added msearch get tests Signed-off-by: Tokesh * renaming folders, using multiple methods, deleting default code Signed-off-by: Tokesh --------- Signed-off-by: Tokesh Signed-off-by: Niyazbek Torekeldi <78027392+Tokesh@users.noreply.github.com> --- CHANGELOG.md | 1 + spec/schemas/_core.msearch_template.yaml | 4 +- .../{msearch.yaml => msearch/index.yaml} | 38 +++---------------- tests/default/_core/msearch/template.yaml | 35 +++++++++++++++++ .../{msearch.yaml => msearch/index.yaml} | 10 ++--- tests/default/indices/msearch/template.yaml | 37 ++++++++++++++++++ 6 files changed, 86 insertions(+), 39 deletions(-) rename tests/default/_core/{msearch.yaml => msearch/index.yaml} (61%) create mode 100644 tests/default/_core/msearch/template.yaml rename tests/default/indices/{msearch.yaml => msearch/index.yaml} (87%) create mode 100644 tests/default/indices/msearch/template.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 32d445c24..94549cf2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixed request schema for `PATCH /_plugins/_security/api/nodesdn` ([#731](https://github.com/opensearch-project/opensearch-api-specification/pull/731)) - Fixed response schema for `GET /_plugins/_security/api/nodesdn/{cluster_name}` ([#731](https://github.com/opensearch-project/opensearch-api-specification/pull/731)) - Fixed request body for `/_search/scroll/{scroll_id}` ([#732](https://github.com/opensearch-project/opensearch-api-specification/pull/732)) +- Fixed type in `_msearch/template` ([#735](https://github.com/opensearch-project/opensearch-api-specification/pull/735)) ### 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/schemas/_core.msearch_template.yaml b/spec/schemas/_core.msearch_template.yaml index f9e164e84..c87bbc3da 100644 --- a/spec/schemas/_core.msearch_template.yaml +++ b/spec/schemas/_core.msearch_template.yaml @@ -25,7 +25,9 @@ components: The value is the variable value. type: object additionalProperties: - type: object + oneOf: + - type: string + - type: object profile: description: When `true`, provides a profile for the query execution. type: boolean diff --git a/tests/default/_core/msearch.yaml b/tests/default/_core/msearch/index.yaml similarity index 61% rename from tests/default/_core/msearch.yaml rename to tests/default/_core/msearch/index.yaml index 6cff72802..7cb893404 100644 --- a/tests/default/_core/msearch.yaml +++ b/tests/default/_core/msearch/index.yaml @@ -1,4 +1,4 @@ -$schema: ../../../json_schemas/test_story.schema.yaml +$schema: ../../../../json_schemas/test_story.schema.yaml description: Test document multi-search. epilogues: @@ -25,7 +25,9 @@ prologues: chapters: - synopsis: Run multiple search requests in single request (GET). path: /_msearch - method: GET + method: + - GET + - POST request: content_type: application/x-ndjson payload: @@ -52,34 +54,4 @@ chapters: - _index: movies _id: movie1 - _index: movies - _id: movie2 - - synopsis: Run multiple search requests in single request (POST). - path: /_msearch - method: POST - request: - content_type: application/x-ndjson - payload: - - {index: movies} - - {query: {match_all: {}}} - - {index: books} - - {query: {match_all: {}}} - response: - status: 200 - payload: - responses: - - hits: - total: - value: 2 - relation: eq - hits: - - _index: movies - _id: movie1 - - _index: movies - _id: movie2 - - hits: - total: - value: 1 - relation: eq - hits: - - _index: books - _id: book1 + _id: movie2 \ No newline at end of file diff --git a/tests/default/_core/msearch/template.yaml b/tests/default/_core/msearch/template.yaml new file mode 100644 index 000000000..f1246f644 --- /dev/null +++ b/tests/default/_core/msearch/template.yaml @@ -0,0 +1,35 @@ +$schema: ../../../../json_schemas/test_story.schema.yaml + +description: Test _msearch/template APIs. +prologues: + - path: /_bulk + method: POST + parameters: + refresh: true + request: + content_type: application/x-ndjson + payload: + - {create: {_index: books, _id: book1}} + - {author: Harper Lee, title: To Kill a Mockingbird, year: 1960} + - {create: {_index: books, _id: book2}} + - {author: Elizabeth Rudnick, title: Beauty and the Beast, year: 1991} + - {create: {_index: books, _id: book3}} + - {author: George Orwell, title: '1984', year: 1949} +epilogues: + - path: /books + method: DELETE + status: [200, 404] + +chapters: + - synopsis: Perform a multi-search template query using a GET request. + path: /_msearch/template + method: + - GET + - POST + request: + content_type: application/x-ndjson + payload: + - {index: books} + - {source: '{"query": {"match": {"title": "{{title}}"}}}', params: {title: Mockingbird}} + - {index: books} + - {source: '{"query": {"match": {"title": "{{title}}"}}}', params: {title: Beast}} \ No newline at end of file diff --git a/tests/default/indices/msearch.yaml b/tests/default/indices/msearch/index.yaml similarity index 87% rename from tests/default/indices/msearch.yaml rename to tests/default/indices/msearch/index.yaml index ba5cd97eb..53fbb7122 100644 --- a/tests/default/indices/msearch.yaml +++ b/tests/default/indices/msearch/index.yaml @@ -1,4 +1,4 @@ -$schema: ../../../json_schemas/test_story.schema.yaml +$schema: ../../../../json_schemas/test_story.schema.yaml description: Test endpoints relevant to the lifecycle of an index, including multi-get and multi-search operations. prologues: @@ -22,7 +22,9 @@ epilogues: chapters: - synopsis: Perform a `_msearch` request to execute multiple search queries in a single call. path: /{index}/_msearch - method: POST + method: + - GET + - POST parameters: index: books request: @@ -31,6 +33,4 @@ chapters: - {index: books} - {query: {match: {title: To Kill a Mockingbird}}} - {index: books} - - {query: {match: {title: The Cruise}}} - response: - status: 200 \ No newline at end of file + - {query: {match: {title: The Cruise}}} \ No newline at end of file diff --git a/tests/default/indices/msearch/template.yaml b/tests/default/indices/msearch/template.yaml new file mode 100644 index 000000000..0586dc449 --- /dev/null +++ b/tests/default/indices/msearch/template.yaml @@ -0,0 +1,37 @@ +$schema: ../../../../json_schemas/test_story.schema.yaml + +description: Test _msearch/template APIs. +prologues: + - path: /_bulk + method: POST + parameters: + refresh: true + request: + content_type: application/x-ndjson + payload: + - {create: {_index: books, _id: book1}} + - {author: Harper Lee, title: To Kill a Mockingbird, year: 1960} + - {create: {_index: books, _id: book2}} + - {author: Elizabeth Rudnick, title: Beauty and the Beast, year: 1991} + - {create: {_index: books, _id: book3}} + - {author: George Orwell, title: '1984', year: 1949} +epilogues: + - path: /books + method: DELETE + status: [200, 404] + +chapters: + - synopsis: Perform a multi-search template query using a GET request. + path: /{index}/_msearch/template + parameters: + index: books + method: + - GET + - POST + request: + content_type: application/x-ndjson + payload: + - {index: books} + - {source: '{"query": {"match": {"title": "{{title}}"}}}', params: {title: Mockingbird}} + - {index: books} + - {source: '{"query": {"match": {"title": "{{title}}"}}}', params: {title: Beast}} \ No newline at end of file