Home / Search/ Language Reference/ Operators/ Display Operators/top

top

The top operator returns the first N events sorted by the specified fields.

top 5 by name is equivalent to the expression sort by name | take 5 both from semantic and performance perspectives.

When sorting different data types, numeric values always appear first.

Syntax

    Scope | top NumberOfRows by Expression [ asc | desc ] [ nulls first | nulls last ]

Arguments

NameTypeRequiredDescription
ScopeTabularYesThe events to search.
NumberOfRowsIntYesThe number of rows to return.
ExpressionStringYesScalar expression by which to sort. The type of the values must be numeric, date, time or string.
asc or descStringNoControls whether the selection is from the “bottom” or “top” of the range. Default desc. Numeric values always appear before other data types.
nulls first or nulls lastStringNoControls whether null values appear at the “bottom” or “top” of the range. Default for asc is nulls first. Default for desc is nulls last.

Examples

Show the top 3 events with the most errors.

dataset=myDataset 
| top 3 by errorCount

Return the top 42 results sorted by the event field in descending order.

dataset=$vt_dummy event<100 
| extend parity=iif(event%2==0, 'even', 'odd') 
| top 42 by event desc