[discuss] sort format in search API
See original GitHub issueversion elasticsearch-js@canary.35
problem:
search
method support sort
parameter that can be configured either in body
or in query
.
The problem is the sort
passed in body
and query
has different syntax.
sort: sortField:sortOrder
syntax is valid in the query
but cannot be used when declared in body.sort
. Unfortunately, it’s hard to realize this syntax is invalid because the Elasticsearch error response will be a cryptic all shard failed
message.
There are several options to fix the problem
- make the client smart enough to detect
sort: sortField:sortOrder
syntax and putsort
parameter in query. Not sure it’s a good option in the long term as it requires theelasticsearch-js
client to cover all the possible API deviations in the future. - reduce API surface to support
sort: SearchSortContainer
only. It doesn’t allowsort: string
shorthand usage anymore but removes ambiguity in the accepted params.
cc @pgayvallet
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Search API sort | Elastic App Search Documentation [8.5]
A special sorting field name is available, _score , to order by relevance. If a sort parameter is not given, results will be...
Read more >REST API Design: Filtering, Sorting, and Pagination - Moesif
Advanced REST API design guidelines for API filtering, sorting, and pagination. ... This is the simplest form of paging. Limit/Offset became popular with ......
Read more >REST API: Sorting, Filtering, and Pagination - Tania Rascia
Sorting allows you to order the results by any field, in ascending or descending order.
Read more >Filtering and sorting search results - Google Developers
Sorted results from your engine are presented based on the value those pages have in their PageMaps for that DataObject and Attribute. Pages...
Read more >Sorting on multiple fields using Search api Sort - Drupal
I want sorting on multiple fields like my custom field in DESC order and Price in ASC order based on some condition.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I see currently in v8.0.0, the type for
sort
inSearchRequest
isstring | string[]
.https://github.com/elastic/elasticsearch-js/blob/main/src/api/types.ts#L969
So I can’t really use the format shown in the docs https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html i.e.
Gives a type error. I have to cast it to
any
to be able to use it.Same problem here. It’s typedef should be
sort: Sort | string | string[];
.