Used to compute multiple aggregate functions over the input.

ParameterTypeRequiredDefault ValueDescription
function[a]array of aggregate functionsoptional[b] count(as=_count) Specifies which aggregate functions to perform on each group.

[a] The parameter name function can be omitted.

[b] Optional parameters use their default value unless explicitly set.

Hide omitted argument names for this function

Show omitted argument names for this function

The stats() function is implicitly present in a fair number of places where a list of subaggregators is given - for example, groupBy(x, function=[min(y), max(y)]) is equivalent to groupBy(x, function=stats([min(y), max(y)])). This is how aggregator results are combined when using those other functions.

The output of stats() is:

  • In case all subaggregators yield at most one row of output (this includes most numerical aggregators), the result will be one combined row.

  • When one or more of the subaggregators of stats() emit more than one result row, the total output is the Cartesian product of all of the subaggregators' outputs, except if any of the subaggregators outputs zero rows, it is taken as it is outputting a single empty row.

  • The output combination is checked for fieldname collisions - and it is an error if a field is present in multiple outputs with conflicting values.

The stats() is also available as a shorthand syntax by writing a list of aggregators in square brackets:

logscale Syntax
...
| stats(function=[min(), max()])

Is equivalent to:

logscale Syntax
...
| [min(),max()]

This produces one row of data that contains both min and max results.

The following query is equivalent to just count():

logscale
stats(function=count())

stats() Examples

Click + next to an example below to get the full details.

Annotate Events With Aggregation - Example 1

Annotate events using stats() function and aggregation

Annotate Events With Aggregation - Example 2

Annotate events using stats() function and aggregation

Annotate Events With Aggregation - Example 3

Annotate events using stats() function and aggregation