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

Added _search with sort: direction. #658

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions spec/schemas/_common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
39 changes: 39 additions & 0 deletions tests/default/_core/search/search_after.yaml
Original file line number Diff line number Diff line change
@@ -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
79 changes: 44 additions & 35 deletions tests/default/_core/search/sort_by_field.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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
Loading