Skip to main content
Version: 5.2

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

Calculating the average number of messages per user by hourly intervals:

Example #1
... | timeaggs span=1h avg(msgNums) by user.keyword

In this example, for each unique value of the user.keyword field, the average number of messages msgNums is calculated for each hourly interval.


Example 2

In this example, for each unique value of the event.outcome field, data is aggregated over a 15-minute time interval with a count of events.

Example #2
... | timeaggs span=15m count by event.outcome

For the sample input data presented below, a bar chart with series grouping is built:

usernamerequestpathstatusevent.outcome
SmithGET/veil200success
TaylorGET/cherry200success
SmithPOST/fuel403failure
JohnGET/quilt200success

Bar chart


Example 3

Calculating the total number of events and the maximum log offset by 3-hour intervals:

Example #3
... | timeaggs composite=true span=3h count, max(log.offset)

Example 4

In this example, for each 5-day interval, the system will return the value of the log.offset field that occurs in 5 percent of cases:

Example №4
... | timeaggs span=5d perc(log.offset, 5)

Example 5

Calculating the maximum network traffic volume for each host by 30-minute intervals with a limit on the number of unique hosts:

In this example, a new field network.kb is created, which converts the values of the network.bytes field to kilobytes; the round command rounds the kilobytes to 2 significant digits and saves them to a new field network.kb_round.

Example №5
... | peval network.kb=network.bytes/1024, network.kb_round=round(network.kb, 2) 
| timeaggs limit=3 span=30m max(network.kb_round) by hostname

For each unique host value hostname, the maximum network traffic volume network.kb_round is calculated for 30-minute intervals. The limit=3 parameter limits the number of unique hosts in the result to three; the remaining hosts are combined into the OTHER column.

| timeaggs limit=3 span=30m max(network.kb_round) by hostname

Sample input data:

hostnamenetwork.bytes@timestamp
SIN723432025-05-26T15:25:39.697685Z
BJS858042025-05-26T15:25:33.003472Z
NN602392025-05-26T15:25:24.338701Z
SIN106462025-05-26T15:25:24.290198Z
BJS106462025-05-26T15:25:25.223198Z

The query execution result may be the following table:

OTHERSINBJSNN_time
99,84nullnull87,42025-05-26T16:00:00.000Z
91,7187,409nullnull2025-05-26T16:30:00.000Z
85.36null89,7515,962025-05-26T16:30:00.000Z

Line chart