Skip to main content
LambdaDB allows you to add one or more sorts on specific fields. Each sort can be reversed as well. The sort is defined on a per field level.
Sorting can be done on the following data types:
  • long
  • double
  • datetime
  • keyword

Request format

Set the request’s sort to an array of objects mapping indexed field names to "asc" or "desc", such as [{"timestamp": "desc"}]. The field name is the object key and the direction is its value; there are no literal field or order properties. Omitting sort or setting it to null means no explicit sort. Native reranking rejects any non-null sort, including an empty array.

Sort order options

Usage

The sort parameter accepts an array of sort objects, allowing multiple field sorting with different orders.

Examples

Single field sort

Sort by timestamp in descending order (newest first):

Multiple field sort

Sort by priority (descending) first, then by created_at (ascending):
When multiple sort fields are specified, the sorting is applied in the order they appear in the array. Documents are first sorted by the first field, then by the second field for documents with the same first field value, and so on.

Keyword array sorting

For keyword arrays, ascending order selects the smallest indexed value and descending order selects the largest. For example, ["a", "z"] sorts using "a" in ascending order and "z" in descending order. Single values follow the same ordering. Values use Unicode code point order, without analysis, locale collation, or case folding. Documents with no indexed keyword value sort last in ascending order and first in descending order. Missing fields, null fields, empty arrays, and values excluded by the keyword length limit have no indexed sort value. Empty strings are indexed values.