nano SIEM
Search Commands

sort

Supported in:Self-hosted

Order rows by one or more fields, ascending or descending, with an optional row limit.

Use sort to order your results by one or more fields. Choose ascending or descending order and set a row limit when you need only part of the result.

Syntax

... | sort [by] [<N>] [+|-]<field> [, [+|-]<field> ...] [limit=<N>]
... | sort [by] [<N>] <field> [asc|desc] [, <field> [asc|desc] ...] [limit=<N>]
ArgumentDefaultDescription
field—The field to sort on. The first field is the primary key; later fields break ties. Separate with commas or spaces. Quote names with spaces.
- / desc—Descending (largest, newest or Z first).
+ / ascascendingAscending (smallest, oldest or A first). A -/+ prefix wins over an asc/desc suffix.
N (before the fields) or limit=Nall rowsKeep only the first N rows after sorting.
by—Optional, for readability (sort by -count).

How it works

  • Event searches without sort come back newest first (time descending). sort time turns them oldest first.
  • After stats, sort on the aggregate's output name. Name aggregates with as so you can sort on them: stats sum(traffic.bytes_out) as sent by src_endpoint.ip | sort -sent. A bare count column is named count.
  • sort N and limit=N are the same as sort … | head N.

Examples

Users with the most failed logons first:

class_uid=3002 status_id=2 | stats count by user.name | sort -count

The five proxy clients that sent the most bytes, using the leading-N form:

metadata.log_source=conduit_proxy | stats sum(traffic.bytes_out) as sent by src_endpoint.ip | sort 5 -sent

Primary and secondary keys, mixing directions:

class_uid=4002 | stats count by http_request.url.hostname, http_response.code | sort http_request.url.hostname, -count

Suffix style with a trailing limit:

class_uid=1007 | stats dc(device.hostname) as hosts by process.name | sort by hosts asc limit=20

Oldest events first:

metadata.log_source=windows_event | sort time | head 20

Notes

  • sort also runs after a nano-side stage (lookup, prevalence, inputlookup, resolve_identity, ai, lateral).
  • stats already orders its output by count descending when it has a count column. Add sort when you need a different order.

What's next

  • head / tail: keep the first or last N rows
  • reverse: flip the current order
  • top / rare: ranked value counts in one step

On this page