Skip to main content

timeaggs

Description

Performs search and generates an array of data distributed along a timeline using the internal mechanisms of the storage system.

danger

The timeaggs command can only be used in a query if it's preceded by other commands that also work with internal storage mechanisms, such as source, search, and peval. This condition must also be met for all subqueries within the query.

Syntax

timeaggs [<composite>] [<span>] [<timefield>] [<limit>] [<useother>] <functions-expression> ["," <functions-expression>] [<by_expression>]

Required Arguments

functions-expression You must use at least one of the following functions:

ParameterSyntaxDescription
countcount | count(<field>)Counts the number of events containing a field. If no field is specified, counts the total number of events.
avgavg(<field>)Calculates the average value of a given field.
dcdc(<field>)Computes the number of unique values in a given field.
maxmax(<field>)Computes the maximum value in a given field.
minmin(<field>)Computes the minimum value in a given field.
sumsum(<field>)Computes the sum of the values in a given field.

Optional Arguments

ParameterSyntaxDefaultDescription
spanspan=<span>see predefined span valuesDefines the interval for distribution of segments.
timefieldtimefield=<field>@timestampName of the field containing the timestamp.
compositecomposite=<boolean>falseAllows for scrolling in aggregations and obtaining all possible segments (buckets) through multiple queries (similar to scroll in stats). Can only be applied when grouping (by fields). The number of segments (buckets) returned in the response is fixed at 1000.
limitlimit=<int>10The maximum number of unique by_field values that can be used in the column names of the result. Remaining values will be merged into the OTHER field.
useotheruseother=<boolean>trueIf set to false, the limit parameter is ignored.
by_expressionby <field>The field name used for grouping values.

The following time formats are allowed: (+|-)<int>(s|m|h|d|w|month):

  • s/sec/secs/second/seconds - seconds
  • m/min/mins/minute/minutes - minutes
  • h/hr/hrs/hour/hours - hours
  • d/day/days - days
  • w/week/weeks - weeks
  • mon/month/months - months
Predefined span values

If no span parameter is specified for the time field, default parameters will apply.

Here's the list of predefined parameters:

Time Intervalspan
last 15 minutes10 seconds
last 60 minutes1 minute
last 4 hours5 minutes
last 24 hours30 minutes
last 7 days1 day
last 30 days1 day
last year1 month
Using composite

The composite argument is available when querying OpenSearch.

Using keyword in OpenSearch

Aggregations in OpenSearch perform statistical operations on numeric fields or text fields of the keyword type. Thus, for text fields, you need to append <fieldname>.keyword, and this is necessary both in specified fields and by fields. For example:

... | timeaggs avg(user.keyword), earliest(country.keyword) by event.keyword, user_count

Query Examples

Example #1
... | timeaggs span=1h avg(msgNums) by user.keyword
Example #2
... | timeaggs span=15m avg(log.offset) by source.keyword
Example #3
... | timeaggs composite=true span=3h count, max(log.offset)