Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Msearch template API tests #735

Merged
merged 7 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added response schema for `PUT` and `DELETE /_plugins/_transform/{id}` ([#722](https://github.com/opensearch-project/opensearch-api-specification/pull/716))
- Added response schema for `GET /_plugins/_knn/warmup/{index}` ([#717](https://github.com/opensearch-project/opensearch-api-specification/pull/717))
- Added support for multiple test verbs ([#724](https://github.com/opensearch-project/opensearch-api-specification/pull/724))
- Added string type in additionalProperties to `msearch template` ([#735](https://github.com/opensearch-project/opensearch-api-specification/pull/735))

### Removed
- Removed unsupported `_common.mapping:SourceField`'s `mode` field and associated `_common.mapping:SourceFieldMode` enum ([#652](https://github.com/opensearch-project/opensearch-api-specification/pull/652))
Expand Down
4 changes: 3 additions & 1 deletion spec/schemas/_core.msearch_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ components:
The value is the variable value.
type: object
additionalProperties:
type: object
oneOf:
- type: string
- type: object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's an example where this is a string? The description says these are key/value pairs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a key-value pair. Here’s one example: link.

Initially, it seems there was an expectation that the value would be in the form of an object, but I demonstrated with an example that it can also be a string.

profile:
description: When `true`, provides a profile for the query execution.
type: boolean
Expand Down
47 changes: 47 additions & 0 deletions tests/default/_core/msearch_template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
$schema: ../../../json_schemas/test_story.schema.yaml

description: Test _termvectors and _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
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}}
response:
status: 200
- synopsis: Perform a multi-search template query using a POST request.
path: /_msearch/template
method: POST
request:
content_type: application/x-ndjson
payload:
- {index: books}
- {source: '{"query": {"match": {"title": "{{title}}"}}}', params: {title: '1984'}}
- {index: books}
- {source: '{"query": {"match": {"author": "{{author}}"}}}', params: {author: Harper Lee}}
response:
status: 200
14 changes: 14 additions & 0 deletions tests/default/indices/msearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ epilogues:
status: [200, 404]
chapters:
- synopsis: Perform a `_msearch` request to execute multiple search queries in a single call.
path: /{index}/_msearch
method: GET
parameters:
index: books
request:
content_type: application/x-ndjson
payload:
- {index: books}
- {query: {match: {title: To Kill a Mockingbird}}}
- {index: books}
- {query: {match: {title: The Cruise}}}
response:
status: 200
- synopsis: Perform a `_msearch` request to execute multiple search queries in a single call (POST).
path: /{index}/_msearch
method: POST
parameters:
Expand Down
51 changes: 51 additions & 0 deletions tests/default/indices/msearch_template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
$schema: ../../../json_schemas/test_story.schema.yaml

description: Test _termvectors and _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
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}}
response:
status: 200
- synopsis: Perform a multi-search template query using a POST request.
path: /{index}/_msearch/template
parameters:
index: books
method: POST
request:
content_type: application/x-ndjson
payload:
- {index: books}
- {source: '{"query": {"match": {"title": "{{title}}"}}}', params: {title: '1984'}}
- {index: books}
- {source: '{"query": {"match": {"author": "{{author}}"}}}', params: {author: Harper Lee}}
response:
status: 200
Loading