Skip to content

Commit

Permalink
Fix _source accepting an array of fields in _search.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <dblock@amazon.com>
  • Loading branch information
dblock committed Jul 17, 2024
1 parent 7e1a233 commit 2fd6d5e
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions spec/schemas/_core.search.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
147 changes: 147 additions & 0 deletions tests/_core/search/_source.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2fd6d5e

Please sign in to comment.