how to set the search {sort} direction (ascending/descending)
See original GitHub issueI am using the {sort: 'field'}
option when using the index.search(options)
API.
How can I set the sort direction (ascending/descending)?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Sort search results | Elasticsearch Guide [8.5] | Elastic
Use the median of all values as sort value. Only applicable for number based array fields. The default sort mode in the ascending...
Read more >How to: Sort a Query Dataset in Ascending or Descending Order
In the Order By window, in the Column field of the first row, choose the AssistEdit button to open the Column List -...
Read more >elasticsearch set sort order using querystring - Stack Overflow
Try sort=anio:desc. See search API - uri request for a list of parameters.
Read more >What is ascending order? What is descending order?
Descending order means the largest or last in the order will appear at the top of the list: For numbers or amounts, the...
Read more >Sorting columns by ascending or descending order in Search ...
In my example, this would be helpful to allow you to view the oldest ticket in the list which hasn't been modified recently...
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 Free
Top 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
One thing I noticed about custom sorting is that it seems to be applied after the limit. So with a limit of 10, you would get the top 10 results based on score, but after that you sort those i.e. on date. However if you then show the second page it can lead to some unexpected results, because the dates don’t start where the first page stopped.
Is the built in “sort” applied before the limit?
I would prefer the
{sort: 'field', order: 'desc'}
Or, alternatively, an extra “sortDirection” field on root level of the config object, which would be backwards compatible if it gets the current order (ascending) by default.