Sorting Data
The sort() is the primary method of sorting event
data:
Top or Bottom N Values
To get the 'top' number of events, the sort() has a
limit parameter to limit the
output; with the addition of the
order parameter this can be
used to sort and order from the highest to the lowest or vice versa. For
example, with this input event set (from a
groupBy()):
| host | _count |
|---|---|
| BACKUP01 | 5 |
| DC01 | 7 |
| DEV-APP01 | 3 |
| DEV-DB01 | 3 |
| DEV-TEST01 | 4 |
| DEV-US-APP02 | 3 |
| DEV-WEB01 | 6 |
| DHCP01 | 7 |
| DNS01 | 2 |
| LON-SRV01 | 7 |
| MAIL01 | 5 |
| NYC-SRV01 | 6 |
| PRINT01 | 5 |
| PROD-APP02 | 5 |
| PROD-DB01 | 6 |
| PROD-EMEA-WEB01 | 3 |
| PROD-FILE01 | 8 |
| PROD-SQL01 | 1 |
| PROD-WEB01 | 4 |
| QA-EU-TEST01 | 3 |
| STG-APAC-DB01 | 3 |
| SYD-SRV01 | 4 |
| TYO-SRV01 | 7 |
The top 5 (by count):
groupby(host)
| sort(_count,order=desc,limit=5)Produces
| host | _count |
|---|---|
| PROD-FILE01 | 8 |
| DC01 | 7 |
| DHCP01 | 7 |
| LON-SRV01 | 7 |
| TYO-SRV01 | 7 |
The bottom 5 (by count):
groupby(host)
| sort(_count,order=asc,limit=5)| host | _count |
|---|---|
| PROD-SQL01 | 1 |
| DNS01 | 2 |
| DEV-APP01 | 3 |
| DEV-DB01 | 3 |
| DEV-US-APP02 | 3 |
If the dataset is large, a quicker approximate value can be obtained
using top().
First and Last by Timestamp
To get the same information ordered by the timestamp data, use the
tail() and head() functions.
These return the last or first events according to the timestamp.
For example, to get the latest event:
host = "DEV-DB01"
| tail(1)Might return:
| @timestamp | #hostname |
|---|---|
| 2025-12-17 06:58:41.799 | DEV-DB01 |
Alternative, if you are looking for only one value, use the
selectFromMin() or
selectFromMax() functions and add
@database as one of the selected values:
selectFromMin(@timestamp, include=[#hostname, @timestamp])Gets the oldest value.