From 2fd6d5e43bca54eafc5f22b34cb2b5e56507c6c0 Mon Sep 17 00:00:00 2001 From: dblock Date: Wed, 17 Jul 2024 09:29:44 -0400 Subject: [PATCH] Fix _source accepting an array of fields in _search. Signed-off-by: dblock --- CHANGELOG.md | 1 + spec/schemas/_core.search.yaml | 3 + .../{ => _core}/mapping/constant_keyword.yaml | 2 +- tests/_core/search/_source.yaml | 147 ++++++++++++++++++ 4 files changed, 152 insertions(+), 1 deletion(-) rename tests/{ => _core}/mapping/constant_keyword.yaml (91%) create mode 100644 tests/_core/search/_source.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c87a449f..e3a019212 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixed `/_mapping` with `index` in query ([#385](https://github.com/opensearch-project/opensearch-api-specification/pull/385)) - Fixed duplicate `/_nodes/{node_id}` path ([#416](https://github.com/opensearch-project/opensearch-api-specification/pull/416)) - Fixed required value for `constant_keyword` field type ([#419](https://github.com/opensearch-project/opensearch-api-specification/pull/419)) +- Fixed `_source` accepting an array of fields in `/_search` ([#430](https://github.com/opensearch-project/opensearch-api-specification/pull/430)) ### Security diff --git a/spec/schemas/_core.search.yaml b/spec/schemas/_core.search.yaml index 8e7350d06..c6e65d005 100644 --- a/spec/schemas/_core.search.yaml +++ b/spec/schemas/_core.search.yaml @@ -789,6 +789,9 @@ components: description: Defines how to fetch a source. Fetching can be disabled entirely, or the source can be filtered. oneOf: - type: boolean + - type: array + items: + $ref: '_common.yaml#/components/schemas/Field' - $ref: '#/components/schemas/SourceFilter' SourceFilter: type: object diff --git a/tests/mapping/constant_keyword.yaml b/tests/_core/mapping/constant_keyword.yaml similarity index 91% rename from tests/mapping/constant_keyword.yaml rename to tests/_core/mapping/constant_keyword.yaml index 0d209edc5..ffdb1e274 100644 --- a/tests/mapping/constant_keyword.yaml +++ b/tests/_core/mapping/constant_keyword.yaml @@ -1,4 +1,4 @@ -$schema: ../../json_schemas/test_story.schema.yaml +$schema: ../../../json_schemas/test_story.schema.yaml description: Test constant_keyword field type and retrieving a doc. version: '>= 2.14' diff --git a/tests/_core/search/_source.yaml b/tests/_core/search/_source.yaml new file mode 100644 index 000000000..973eb3585 --- /dev/null +++ b/tests/_core/search/_source.yaml @@ -0,0 +1,147 @@ +$schema: ../../../json_schemas/test_story.schema.yaml + +description: Test search endpoint (_source). +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 (_source=true). + path: /{index}/_search + parameters: + index: movies + method: POST + request_body: + payload: + _source: true + 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 (_source=false). + path: /{index}/_search + parameters: + index: movies + method: POST + request_body: + payload: + _source: false + query: + match_all: {} + response: + status: 200 + payload: + timed_out: false + hits: + total: + value: 1 + relation: eq + max_score: 1 + hits: + - _index: movies + _score: 1 + - synopsis: Search (_source=[fields]). + path: /{index}/_search + parameters: + index: movies + method: POST + request_body: + payload: + _source: + - director + - year + 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 + year: 2011 + - synopsis: Search (_source=filter). + path: /{index}/_search + parameters: + index: movies + method: POST + request_body: + payload: + _source: + includes: director + excludes: year + 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 + - synopsis: Search (_source=filter with wildcards). + path: /{index}/_search + parameters: + index: movies + method: POST + request_body: + payload: + _source: + includes: '*' + excludes: year + 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