question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to set the search {sort} direction (ascending/descending)

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
desjobcommented, Jul 16, 2019

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?

1reaction
desjobcommented, Jul 16, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found