On this page
sort command
Sort the result set. Prefix a field with - for descending.
Orders the result rows by one or more fields. Fields sort ascending unless prefixed with -, which sorts descending.
It works on raw events and on the output of stats, timechart, eval and the other stages.
Syntax
ObiQL
| sort [-|+]<field> [, [-|+]<field> ...]Square brackets mark an optional part, and angle brackets a value you supply.
Arguments
| Argument | Required | Description |
|---|---|---|
<field> | Required | A field or result column to sort by. Prefix it with - for descending or + (the default) for ascending. Quote a name that contains a space: | sort -"Total Errors". |
Usage
- A field with a known type sorts as that type: the timestamp by time, and numbers from eval or an aggregation numerically.
- Other event fields are stored as text, so values that look like numbers sort numerically and come before values that do not, which sort as text.
| sort -amountputs100ahead of10ahead of9. - Rows missing the field sort last in both directions.
- Without a sort, events come back newest first.
- sort cannot follow dedup. Put the sort first to choose which row dedup keeps.
Examples
1. Busiest services first
ObiQL
| stats count() by service | sort -countSorts the aggregate by its count column, largest first.
2. Slowest requests
ObiQL
service=checkout-api | sort -duration_ms | limit 20The twenty slowest requests in the time range.
3. Sort by several fields
ObiQL
| stats count() by service, level | sort service, -countGroups the rows by service alphabetically, then by count within each service.