stats
stats
TablePerform aggregations over your data, optionally grouped by one or more fields.
| stats [agg1(field1) as alias1, ...] [by groupField1, groupField2, ...] | stats count() as total, avg(duration) as avg_dur by service Parameters
Section titled “Parameters”The stats command supports the following patterns:
agg(field) as alias: Aggregation function (see below) applied to a field, optionally renamed withas.by groupField1, ...: (Optional) Group results by one or more fields.
Available Aggregation Functions
Section titled “Available Aggregation Functions”count(): Counts the number of records in each group (or overall if no grouping).sum(field): Sums the values offieldfor each group.avg(field): Calculates the average value offieldfor each group.min(field): Finds the minimum value offieldfor each group.max(field): Finds the maximum value offieldfor each group.first(field): Returns the first non-null value offieldin each group.last(field): Returns the last non-null value offieldin each group.
You can use multiple aggregation functions in a single
statscommand, and each can be given an alias usingas.
- Use
statsto summarize data, such as counting events or calculating averages. - Multiple aggregations and groupings are supported.
Example
Section titled “Example”| stats count() as total, avg(duration) as avg_duration, first(user) as first_user by status
This counts all records, calculates the average duration, and returns the first user for each status group.