Available:slidingTimeWindow() v1.174.0

The slidingTimeWindow() function is available from version 1.174.0.

The slidingTimeWindow() function applies an aggregation to a moving time-based window of events in a sequence. It is useful for calculating metrics over a fixed time period, allowing for time-based trend analysis and data smoothing.

The difference between slidingTimeWindow() and window() is that window() spans multiple buckets and accumulates events inside the bucket, whereas slidingTimeWindow() does not use buckets, but simply accumulates across the incoming events within a specified span.

For more information about sequence functions and combined usage, see Sequence Query Functions.

ParameterTypeRequiredDefault ValueDescription
currentenumoptional[a] include Controls whether to include the current event in the window calculation.
   Valid Values
   excludeExclude current event in window calculation
   includeInclude current event in window calculation
function[b]array of aggregate functionsrequired   The aggregator function(s) to apply to each time window. It only accepts functions that output at most a single event.
spanstringrequired   The duration of the time window (for example, 1h, 30m, 1d).
timestampfieldstringoptional[a] Either @timestamp or @ingestTimestamp depending on what is selected for the query. Specifies the field to use as the timestamp for calculations.

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

[b] The parameter name function can be omitted.

Hide omitted argument names for this function

Show omitted argument names for this function

Note

  • The slidingTimeWindow() function must be used after an aggregator function (for example, head(), sort(), bucket(), groupBy() timeChart()) to ensure event ordering, as the slidingTimeWindow() function requires a specific order to calculate cumulative values correctly.

  • Only functions (for example, sum(), avg(), count()) that output a single event can be used in the sub-aggregation because the slidingTimeWindow() function needs a single value to add to its running total for each event.

  • The window can contain a maximum of 10000 events.

  • Events must be sorted in order by timestamp. Unordered or missing timestamps will result in errors.

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

Detect Event A Happening X Times Before Event B Within a Specific Timespan

Detect event A happening X times before event B within a specific timespan using the slidingTimeWindow() function combined with groupBy()

Detect Two Events Occurring in Quick Succession

Detect event B occurring quickly after event A using the slidingTimeWindow() function