diff --git a/CHANGELOG.md b/CHANGELOG.md index 811c2cb21..c34b38a77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added API specs for query groups lifecycle APIs ([#649](https://github.com/opensearch-project/opensearch-api-specification/pull/649)) - Added Python and Ruby spec validators ([#646](https://github.com/opensearch-project/opensearch-api-specification/pull/646)) - Added verbose output of the story being evaluated ([#646](https://github.com/opensearch-project/opensearch-api-specification/pull/646)) +- Added `_search` with `sort: direction` ([#658](https://github.com/opensearch-project/opensearch-api-specification/pull/658)) ### 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)) diff --git a/spec/schemas/_common.yaml b/spec/schemas/_common.yaml index 6450e9c6d..883ac273a 100644 --- a/spec/schemas/_common.yaml +++ b/spec/schemas/_common.yaml @@ -558,10 +558,16 @@ components: oneOf: - title: field $ref: '#/components/schemas/Field' + - title: field_with_direction + $ref: '#/components/schemas/FieldWithDirection' - title: field_with_order $ref: '#/components/schemas/FieldWithOrder' - title: options $ref: '#/components/schemas/SortOptions' + FieldWithDirection: + type: object + additionalProperties: + $ref: '#/components/schemas/SortOrder' FieldWithOrder: type: object additionalProperties: diff --git a/tests/default/_core/search/search_after.yaml b/tests/default/_core/search/search_after.yaml new file mode 100644 index 000000000..0da17c906 --- /dev/null +++ b/tests/default/_core/search/search_after.yaml @@ -0,0 +1,39 @@ +$schema: ../../../../json_schemas/test_story.schema.yaml + +description: Test search endpoint with search_after. +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}} + - {title: The Cruise, year: 1998} + - {create: {_index: movies}} + - {title: Drive, year: 1960} +chapters: + - synopsis: Search with search_after. + path: /{index}/_search + parameters: + index: movies + request: + payload: + sort: + - year: asc + search_after: + - 1960 + method: POST + response: + status: 200 + payload: + hits: + hits: + - _source: + title: The Cruise + year: 1998 diff --git a/tests/default/_core/search/sort_by_field.yaml b/tests/default/_core/search/sort_by_field.yaml index 4256929ee..ff9329286 100644 --- a/tests/default/_core/search/sort_by_field.yaml +++ b/tests/default/_core/search/sort_by_field.yaml @@ -3,12 +3,12 @@ $schema: ../../../../json_schemas/test_story.schema.yaml description: Test different ways to sort by field. epilogues: - - path: /sorted_movies + - path: /movies method: DELETE status: [200] prologues: - - path: /sorted_movies + - path: /movies method: PUT request: payload: @@ -18,40 +18,25 @@ prologues: type: keyword year: type: integer - - - path: /sorted_movies/_doc - method: POST - parameters: - refresh: true - request: - payload: - title: The Lion King - year: 1994 - status: [201] - - path: /sorted_movies/_doc - method: POST - parameters: - refresh: true - request: - payload: - title: The Lion King - year: 2019 - status: [201] - - path: /sorted_movies/_doc + - path: /_bulk method: POST parameters: refresh: true request: + content_type: application/x-ndjson payload: - title: Frozen - year: 2013 - status: [201] + - {create: {_index: movies}} + - {title: The Lion King, year: 1994} + - {create: {_index: movies}} + - {title: The Lion King, year: 2019} + - {create: {_index: movies}} + - {title: Frozen, year: 2013} chapters: - - synopsis: QueryString Sort by year. + - synopsis: Sort by year. path: /{index}/_search parameters: - index: sorted_movies + index: movies sort: year method: GET response: @@ -69,10 +54,10 @@ chapters: title: The Lion King year: 2019 - - synopsis: QueryString Sort by title:desc. + - synopsis: Sort by title:desc. path: /{index}/_search parameters: - index: sorted_movies + index: movies sort: title:desc method: GET response: @@ -90,10 +75,10 @@ chapters: title: Frozen year: 2013 - - synopsis: QueryString Sort by title:desc,year:desc. + - synopsis: Sort by title:desc,year:desc. path: /{index}/_search parameters: - index: sorted_movies + index: movies sort: title:desc,year:desc method: GET response: @@ -111,10 +96,10 @@ chapters: title: Frozen year: 2013 - - synopsis: Body Sort by [title, year]. + - synopsis: Sort by [title, year]. path: /{index}/_search parameters: - index: sorted_movies + index: movies method: GET request: payload: @@ -136,10 +121,10 @@ chapters: title: The Lion King year: 2019 - - synopsis: Body Sort by year:asc,title:desc. + - synopsis: Sort by year:asc,title:desc. path: /{index}/_search parameters: - index: sorted_movies + index: movies method: GET request: payload: @@ -161,3 +146,27 @@ chapters: title: The Lion King year: 1994 + - synopsis: Sort with direction by year:asc,title:desc. + path: /{index}/_search + parameters: + index: movies + method: GET + request: + payload: + sort: + - title: asc + - year: desc + response: + status: 200 + payload: + hits: + hits: + - _source: + title: Frozen + year: 2013 + - _source: + title: The Lion King + year: 2019 + - _source: + title: The Lion King + year: 1994