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

Parameters

ParameterDescriptionTypeRequiredValues
fieldField name to sort bystring-
orderSort order directionstringasc, desc

Sort order options

ValueDescription
ascSorts in ascending order
descSorts in descending order

Usage

The sort parameter accepts an array of sort objects, allowing multiple field sorting with different orders.
Python
lambda_db = LambdaDB(
    server_url="PROJECT_URL",
    project_api_key="YOUR_API_KEY",
)

results = lambda_db.collections.query(
    collection_name=collection_name,
    query={
        "queryString": {
            "query": "*:*"
        }
    },
    size=10,
    sort=[{"field1": "desc"}, {"field2": "asc"}],
)

Examples

Single field sort

# Sort by timestamp in descending order (newest first)
sort=[{"timestamp": "desc"}]

Multiple field sort

# Sort by priority (desc) first, then by created_at (asc)
[{"priority": "desc"}, {"created_at": "asc"}]
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.