aggr
Use aggregation functions to summarize results as a single value (or an array).
You can also drilldown on the aggregated values to launch a new search that uses these aggregated values as a filter in the where operator and display more details about these specific values. See Aggregate, Sort, and Limit Result Rows for more information.
Syntax
|aggr <aggr function> [as new_field] [, <aggr function> [as new_field], ...] by <field> [, <field>, ...]
Usage
Use aggr to drilldown on the aggregated values to launch a new search that uses these aggregated values as a filter in the where operator and display more details about these specific values. See Aggregate, Sort, and Limit Result Rows for more information.
aggr supports the following aggregation functions:
| Function | Usage |
|---|---|
|
|
Return an array of distinct result values. The Note: This function consumes significant memory to store aggregated values. See AQL Best Practices to use |
avg()
|
Return the average of result values. Applies to numeric and date fields. |
count()
|
Return a count of results. |
count(distinct <field>)
|
Return a count of distinct values in results. |
|
|
Return a count of distinct values in results. |
distinct()
|
Returns distinct values for the specified field. |
first()
|
Returns the first entry in a result set. For more information, see first. |
last()
|
Returns the last entry in a result set. For more information, see last. |
latest()
|
Returns the latest or the most recent entry in a result set. |
max()
|
Return the highest value among results. Applies to numeric and date fields. |
median()
|
Return the middle value of ordered results. Applies to numeric and date fields. |
min()
|
Return the lowest value among results. Applies to numeric and date fields. |
mode()
|
Return the most frequent value of the specified field. Applies to numeric and date fields. |
perc()
|
Return the specified percentile value of the specified field. Applies to numeric fields only. The function has the following syntax:
The following example returns the 25th percentile value for the volume field:
|
range()
|
Return the difference between the lowest and highest value for the specified field. Applies to numeric fields. |
sparkline[(<func>(<field>), <timespan>)]
|
Returns one or more columns having a series of computed values to plot a sparkline visualization. The maximum number of buckets is 60. If you do not specify options, the default aggregation function is You can specify one of the following options:
Copy
|
stdev()
|
Return the sample standard deviation for the set of values returned the specified field. |
stdevp()
|
Return the population standard deviation for the set of values returned the specified field. |
sum()
|
Return the sum of result values. Applies to numeric and date fields. |
var()
|
Return the sample variance of a data set. Applies to numeric and date fields. Example:
Note: In a complex AQL expression that includes |
Examples
Note: For OCSF schema fields, array indexes start at array[1] and not array[0].
Example 1: Aggregate distinct source port values grouped by source port.
|aggr array_agg(src_port) by src_port
Example 2: Calculate the average of incoming bytes.
|aggr avg(bytes_in)
Example 3: Count events grouped by source address.
|aggr count by src
Example 4: Count distinct source addresses with a custom result field name.
|aggr count(distinct src) as distinct_sources
Example 5: Find the highest destination port value.
|aggr max(dest_port)
Example 6: Calculate the range of byte values.
|aggr range(bytes_in)
Example 7: Calculate standard deviation of an age field.
|aggr stdev(age)
Example 8: Visualize data with sparklines grouped by source type.
|aggr sparkline, count as cnt by sourcetype
Example 10: Counts the number of unique source IPs per OCSF event category.
ocsf | aggr count(distinct src_endpoint.ip) by category_uid
Example 11: Generates a sparkline of hourly OCSF event counts per product name, visualizing activity trends for each security source in a compact inline chart.
ocsf | aggr sparkline(count(class_name), 1h) as sparkline_action by metadata.product.name