Aggregation¶
Aggregations collapse matching logs into counts, statistics and groups. Use them to summarize activity, find top talkers, or spot outliers.

Output columns¶
Each aggregate names its column after itself with a leading underscore: count() gives _count, sum() gives _sum. Use that name in later filters, sort() and table().
as= renames the column. It is required when two aggregates of the same kind share a stage:
After an aggregation only its group keys and output columns exist. Filter on them with a later |:
Group by¶
Without function=, each group gets _count. Pass function= for a different aggregate, or multi() for several:
| Parameter | Description |
|---|---|
| fields | One or more fields or expressions to group by |
function= |
Aggregate per group. Default: count() |
limit= |
Maximum number of groups returned |
distinct= |
Count the distinct values of the last field per group of the others, as _count: groupBy(src_ip, dst_ip, distinct=true) is the destinations each source reached |
A bare | count() after groupBy() counts the groups, not the rows in each:
Basic aggregates¶
| Function | Output | Description |
|---|---|---|
count() |
_count |
Number of rows |
count(field, unique=true) |
_count |
Number of distinct values. distinct=true is the same |
sum(field) |
_sum |
Total |
avg(field) |
_avg |
Mean |
min(field) / max(field) |
_min / _max |
Smallest or largest value. Works on timestamp |
median(field) |
_median |
Median |
percentile(field) |
_percentile |
The p50, p75 and p99 values. Not configurable |
stddev(field) |
_stddev |
Population standard deviation. Alias stdDev |
skewness(field) |
_skewness |
Population skewness. Alias skew |
kurtosis(field) |
_kurtosis |
Population excess kurtosis. Alias kurt |
selectFirst(field) |
_first |
Value from the earliest event |
selectLast(field) |
_last |
Value from the latest event |
Note
count(field) counts every row, including rows without the field. To count only rows that have it, filter first: user=* | count().
Statistical aggregates also work on a previous aggregation's output, for example the spread of per-host counts:
MAD¶
mad() is the median absolute deviation (_mad), a measure of spread that extreme values do not skew. As a standalone command it also returns _median.
Correlation¶
| Function | Output | Measures |
|---|---|---|
corr(x, y) |
_corr |
Pearson: how closely the two follow a straight line |
rankcorr(x, y) |
_rankcorr |
Spearman: whether one rises when the other does |
Values run from -1 (one falls as the other rises) through 0 (no relationship) to 1 (rise together). Both are empty for fewer than two rows or a constant field. Prefer rankcorr() for byte counts, durations and other heavy-tailed fields, where a few huge values can dominate corr(). Groups over 100,000 rows are ranked from a random sample, so rankcorr() can vary by about 0.003 between runs.
Multi¶
multi() computes several aggregates in one stage:
Inside multi() or function=, aggregates take named arguments: count(field=event_id, distinct=true, as=unique_events). Two extra aggregates are available there:
| Function | Output | Description |
|---|---|---|
collect(field) |
_collect |
All values of the field in the group, as an array |
top(field, percent=true) |
_top |
The 10 most frequent values, with counts, or percentages when percent=true |
Top¶
Returns the most frequent values of a field as _top. Default limit= is 10. percent=true shows each value's share of rows instead of its count.
Frequency¶
A frequency table, sorted by count: _value, _count, _percentage and _cumulative_pct.
Head/tail (Pareto)¶
Same columns as frequency(), plus _segment: head for values within the first threshold percent of rows (default 80), tail for the rest.
IQR¶
Returns _q1 (25th percentile), _q3 (75th percentile) and _iqr (Q3 minus Q1).
Modified z-score¶
Adds _median, _mad and _modified_z to each row, where _modified_z = 0.6745 * (x - median) / MAD. Robust to outliers. Aliases modifiedz, mzscore.
MAD outlier¶
Same as modifiedZScore() plus _is_outlier: 1 when |_modified_z| exceeds threshold (default 3.5), else 0. Alias outlier.
A filter after either keeps scored rows: madOutlier(latency) | host="web1" scores web1 against every row, while host="web1" | madOutlier(latency) scores it against itself.
Analyze fields¶
Per-field statistics: field_name, _events, _distinct_vals, _mean, _min, _max, _stdev. With no fields it analyzes all of them. Scans the first 50,000 rows by default; limit= raises that up to 200,000.