Available: statistics:holtWinters()
v1.269.0
The statistics:holtWinters() function is
available from version 1.269.0.
The statistics:holtWinters() function
models and forecasts a series of numeric values. The
statistics:holtWinters() function uses the
Holt-Winters method to produce forecasts. This method applies
exponential smoothing to each of three components:
| Component | Description | Smoothing parameter |
|---|---|---|
| Level | The smoothed average value, without the seasonal effect |
baselineConstant (alpha)
|
| Trend | The change in level from one event to the next |
slopeConstant (beta)
|
| Seasonal component |
A pattern that repeats every cycleLength events
|
seasonalityConstant (gamma)
|
A cycle is one complete repetition of the seasonal pattern.
The model must learn the seasonal pattern before it can predict
values. The model learns this pattern from the first two full
cycles of events. This learning period is the
warm-up. The warm-up contains 2 ×
cycleLength
events.
The statistics:holtWinters() function
writes each prediction to the
as
field. The
as
parameter sets the name of this field. By default, the
as
field is _prediction.
The statistics:holtWinters() function
returns three types of events in the following order:
Warm-up events: The function returns the first 2 ×
cycleLengthinput events unchanged. These events have no prediction.Input events with a prediction: The function adds the
asfield (default_prediction) to every later input event. The field contains the prediction of the model for that event.Forecast events: The function adds new events after the last input event. Each forecast event contains a forecast value in the
asfield. It also contains a timestamp if the function can calculate one.
To select events by type, add a filter after the function. Filter on the fields that the function sets:
_prediction=*returns only events with a prediction, which includes forecast events. Use this filter to compare actual values with predicted values. If you set theasparameter, use that field name instead.returns only forecast events. Use this filter to chart or export only the forecast. Replacefield!=*fieldwith the value of thefieldparameter.
Typical use cases include the following tasks:
Forecast the next values of a periodic metric. For example, forecast hourly request counts with a daily pattern (
cycleLength=24).Find anomalies by comparing actual values with predicted values. For example, pass the input field and the
asfield to a latermath:rangeOutliers()call, or compare them with a plain comparison, such astest().Extend a time series graph with a short forecast.
Example:
sort(@timestamp, order=asc)
| statistics:holtWinters(field=requests, cycleLength=24)Example of anomaly detection:
sort(@timestamp, order=asc)
| statistics:holtWinters(field=requests, cycleLength=24)
| math:rangeOutliers(field=requests, low=_prediction * 0.8, high=_prediction * 1.2)
This query finds all time intervals where the number of incoming
requests differs from the expected number by more than 20%.
Warm-up events and forecast events lack one of the required
fields. As a result, math:rangeOutliers()
drops them.
| Signature | statistics:holtWinters([as], [baselineConstant], cycleLength, field, [forecastLength], [seasonalityConstant], [seasonalityMode], [slopeConstant]) |
statistics:holtWinters()| Parameter | Type | Interpreted Type | Required | Default Value | Description |
|---|---|---|---|---|---|
as | Â | string | optional[a] | _prediction | The name of the as field. The value must be a field name. The default is _prediction. This field contains predictions on input events and forecast values on forecast events. |
baselineConstant | Â | number | optional[a] | 0.3 | The smoothing constant for the level, also called alpha. Higher values make the level follow recent events more closely. |
| Â | Â | Â | Minimum | 0 | Â |
| Â | Â | Â | Maximum | 1 | Â |
cycleLength | Â | integer | required | Â | The number of events in one cycle. |
| Â | Â | Â | Minimum | 2 | Â |
field[b] | Â | string | required | Â | The input field that contains the values to model. The value must be a field name. The function removes events with no numeric value in this field. |
forecastLength | Â | integer | optional[a] | 1 | The number of forecast events to add after the last input event. |
| Â | Â | Â | Minimum | 1 | Â |
seasonalityConstant | Â | number | optional[a] | 0.1 | The smoothing constant for the seasonal component, also called gamma. Higher values make the seasonal component follow recent cycles more closely. |
| Â | Â | Â | Minimum | 0 | Â |
| Â | Â | Â | Maximum | 1 | Â |
seasonalityMode | Â | string | optional[a] | multiplicative | The method that combines the seasonal component with the level. For more information, see Seasonality Modes. |
| Â | Â | Â | Â | Values | |
| Â | Â | Â | Â | additive | The seasonal component is a fixed offset that the model adds to the level. |
| Â | Â | Â | Â | multiplicative | The seasonal component is a factor. The seasonal effect increases and decreases with the level. |
slopeConstant | Â | number | optional[a] | 0.1 | The smoothing constant for the trend, also called beta. Higher values make the trend follow recent changes more closely. |
| Â | Â | Â | Minimum | 0 | Â |
| Â | Â | Â | Maximum | 1 | Â |
[a] Optional parameters use their default value unless explicitly set. | |||||
Hide omitted argument names for this function
Omitted Argument NamesThe argument name for
fieldcan be omitted; the following forms of this function are equivalent:logscale Syntaxstatistics:holtWinters("value",cycleLength="value")and:
logscale Syntaxstatistics:holtWinters(field="value",cycleLength="value")These examples show basic structure only.
statistics:holtWinters() Function Operation
The statistics:holtWinters() function has
specific implementation and operational considerations,
outlined below.
Smoothing Constants
The smoothing constants control how quickly each component adapts.
| Value | Effect |
|---|---|
0
| The component keeps its initial estimate. |
1
| The component reflects only the latest value. |
Any number from 0 to 1
| The component changes gradually between these two extremes. A higher value moves it closer to the latest value. |
Input Requirements
Event Order and Spacing
The statistics:holtWinters() function
treats events as an ordered series. Each event is one step
in the series.
The model ignores timestamps during modeling. For example,
events one second apart count as one step. Events one hour
apart also count as one step. As a result,
cycleLength
and
forecastLength
count events, not time units. The function reads
timestamps only to place forecast events in time. For more
information, see
Forecast Phase.
The statistics:holtWinters() function
processes events in the order that it receives them. To
prepare the input, complete the following tasks:
Required: Sort the events before you call the function. In most queries, sort with
sort(@timestamp, order=asc). Alternatively, sort on a bucket field.Required: Space the events evenly.
Required for time-based cycles: Bucket the data into exactly one event for each time slot. Every time slot must contain an event, including slots with no activity.
Query Placement
The statistics:holtWinters() function
is an aggregate function. Place it after another aggregate
function, such as sort(),
bucket(), or
groupBy().
statistics:holtWinters() runs once on
the full output of the previous aggregate function.
The statistics:holtWinters() function
models one series per query. To model multiple groups,
filter the data to one group first.
Note
Do not call the
statistics:holtWinters() function
inside a Cartesian products. For
example, a stats() function can
contain several functions that each return multiple
events. This combination creates a cartesian product. In
this case, the query fails.
Data from Persisted Aggregations
Data from readPersistedAggregation()
is often evenly spaced. Each stored bucket covers one
fixed time interval. For rolled-up data, each bucket
covers one span. The @timestamp field
of each bucket contains the start time of the bucket.
Some persisted aggregations produce one row for each
bucket. For example, count() without
groupBy() produces one row for each
bucket. These rows form a series that the function can
process directly. For more information, see
Forecast from a persisted aggregation.
Behavior
The statistics:holtWinters() function
processes events in three phases: warm-up, prediction, and
forecast.
Warm-up Phase
The statistics:holtWinters() function
collects the first 2 ×
cycleLength
events with a numeric value in the input field. From these
events, the function calculates the following initial
estimates:
Level: The mean of the first cycle.
Trend: The difference in level between the first cycle and the second cycle.
Seasonal component: The distance of each cycle position above or below the average.
Next, the statistics:holtWinters()
function processes the warm-up values one at a time, in
sequence. This step refines the initial estimates.
Note
The
statistics:holtWinters()function
returns warm-up events unchanged. Warm-up events never
contain the
as
field.
Prediction Phase
For each later event, the model performs the following steps in sequence:
Predict: The model calculates a prediction and writes it to the
asfield. The prediction combines the level, one step of trend, and the current seasonal component. For more information, see Seasonality Modes.Update: The model reads the actual value and updates its components.
The model calculates each prediction before it reads the
value of the event. As a result, the prediction is
independent of that value. A large difference between the
input field and the
as
field indicates an unusual event.
A prediction can be NaN or infinite.
For example, input values near the largest
double-precision value can cause an overflow. In this
case, the function omits the prediction and reports a
warning. For an input event, the function returns the
event without the
as
field. For a forecast event, the function does not add the
event.
Forecast Phase
After the last input event, the function adds forecast
events. The
forecastLength
parameter sets the number of forecast events. Each
forecast event has a position, called
k. The first forecast event is position
1, the second is position
2, and so on. Forecast event
k is k steps after
the last input event.
Each forecast value combines the following values:
The last level.
ksteps of trend.The seasonal component at that cycle position.
The model learns only from input values. As a result, a long forecast repeats the last cycle along a straight trend line.
Each forecast event contains only the following fields:
The
asfield: The forecast value.Timestamp field: The calculated time of the forecast event. By default, this field is @timestamp. If the query runs on ingest time, this field is @ingesttimestamp.
The function calculates each forecast timestamp with the following formula:
forecast timestamp = last input timestamp + (k × gap)The gap is the time between the first two events with a numeric value. The function ignores the spacing of later events.
If either of the first two events lacks a timestamp, the gap is unknown. In this case, forecast events have no timestamp field. For example, some aggregations produce events without a timestamp.
Events Without a Numeric Value
The function removes events from the output where the
field
parameter has a missing or non-numeric value. These events
do not count as steps in the series. The model runs as if
these events do not exist.
The function does not insert replacement values. As a result, missing values shorten the series. Missing values can also shift the cycle positions of later events.
The string NaN is an exception. The
function treats the string NaN as a
numeric value, not as a non-numeric value. A
NaN value propagates into the level and
trend. As a result, all later predictions are
NaN, and the function omits them.
Insufficient Data
The warm-up requires 2 ×
cycleLength
events with a numeric value. If the input contains fewer
events, the warm-up does not finish. In this case, the
function performs the following actions:
Returns all events unchanged.
Adds no forecast events.
Reports a warning.
Seasonality Modes
The
seasonalityMode
parameter sets how the seasonal component combines with the
level.
| Mode | Seasonal component | Example data | Recommended for |
|---|---|---|---|
multiplicative (default)
| A factor. The seasonal effect increases and decreases with the level. | Web traffic with a daily peak of about twice the daily average. |
Values that remain well above 0.
|
additive
| A fixed offset that the model adds to the level. | A temperature that varies by about ±5 degrees every day. The size of this variation is independent of the average. |
Values with a constant variation size. Also values that can be 0 or negative.
|
In
multiplicative
mode, each seasonal factor is a ratio to the level. Levels
near 0 can produce inaccurate or very
large factors. Series that cross 0 can
produce meaningless factors. For this type of data, select
additive
mode.
statistics:holtWinters() Syntax Examples
Each example sorts events by @timestamp in ascending order. Unless an example states otherwise, timestamps are one hour apart.
Timestamps are in Unix epoch milliseconds. For example,
1451606400000 is 1 January 2016, 00:00 UTC.
In the input and result listings, an empty value means that the event does not contain that field.
Quarterly salesThis example models and forecasts quarterly sales.
This example models six years of quarterly sales data. The data comes from the NIST/SEMATECH e-Handbook of Statistical Methods. Sales increase every year. The third quarter always has the highest sales.
The query sets the following parameter values:
cycleLength=4: One cycle is one year. As a result, the first two years are the warm-up.forecastLength=4: The function forecasts the next year.Smoothing constants: These values match the values in the handbook example.
Each @timestamp value is the start of its quarter, simplified to 90 days apart. This simplification keeps the series evenly spaced.
sort(@timestamp, order=asc)
| statistics:holtWinters(field=sales, cycleLength=4, forecastLength=4, baselineConstant=0.7556, slopeConstant=0, seasonalityConstant=0.9837)If event data looks like this:
| @timestamp | sales |
|---|---|
| 1451606400000 | 362 |
| 1459382400000 | 385 |
| 1467158400000 | 432 |
| 1474934400000 | 341 |
| 1482710400000 | 382 |
| 1490486400000 | 409 |
| 1498262400000 | 498 |
| 1506038400000 | 387 |
| 1513814400000 | 473 |
| 1521590400000 | 513 |
| 1529366400000 | 582 |
| 1537142400000 | 474 |
| 1544918400000 | 544 |
| 1552694400000 | 582 |
| 1560470400000 | 681 |
| 1568246400000 | 557 |
| 1576022400000 | 628 |
| 1583798400000 | 707 |
| 1591574400000 | 773 |
| 1599350400000 | 592 |
| 1607126400000 | 627 |
| 1614902400000 | 725 |
| 1622678400000 | 854 |
| 1630454400000 | 661 |
it would return:
| @timestamp | sales | _prediction |
|---|---|---|
| 1451606400000 | 362 | <no value> |
| 1459382400000 | 385 | <no value> |
| 1467158400000 | 432 | <no value> |
| 1474934400000 | 341 | <no value> |
| 1482710400000 | 382 | <no value> |
| 1490486400000 | 409 | <no value> |
| 1498262400000 | 498 | <no value> |
| 1506038400000 | 387 | <no value> |
| 1513814400000 | 473 | 472.6783251204108 |
| 1521590400000 | 513 | 512.819245596629 |
| 1529366400000 | 582 | 581.8711685205286 |
| 1537142400000 | 474 | 474.278735019053 |
| 1544918400000 | 544 | 543.887818599726 |
| 1552694400000 | 582 | 581.8391191906799 |
| 1560470400000 | 681 | 680.7583922694411 |
| 1568246400000 | 557 | 557.1718297096573 |
| 1576022400000 | 628 | 627.9805715539404 |
| 1583798400000 | 707 | 706.7063636443364 |
| 1591574400000 | 773 | 772.9033485285262 |
| 1599350400000 | 592 | 592.2817872743749 |
| 1607126400000 | 627 | 627.2181524515316 |
| 1614902400000 | 725 | 724.7498653945511 |
| 1622678400000 | 854 | 853.6157099345223 |
| 1630454400000 | 661 | 661.121647332818 |
| 1638230400000 | <no value> | 752.3916735092856 |
| 1646006400000 | <no value> | 809.2209663778008 |
| 1653782400000 | <no value> | 868.1841716231351 |
| 1661558400000 | <no value> | 695.4674617504612 |
The output contains all three types of events:
Warm-up events: Rows 1 to 8, the first two years.
Input events with a prediction: Rows 9 to 24, the third year to the sixth year.
Forecast events: Rows 25 to 28. These events are 90 days apart. They contain only the
asfield and the @timestamp field.
This example shows predictions and a forecast with a renamed
as
field.
In this example, cycleLength=2 sets a warm-up of
4 events. The fifth and sixth events receive a prediction. The
function then adds one forecast event. The
as
parameter renames the
as
field to myForecast.
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=2, as=myForecast)If event data looks like this:
| @timestamp | value |
|---|---|
| 1451606400000 | 10 |
| 1451610000000 | 12 |
| 1451613600000 | 9 |
| 1451617200000 | 13 |
| 1451620800000 | 11 |
| 1451624400000 | 14 |
it would return:
| @timestamp | value | myForecast |
|---|---|---|
| 1451606400000 | 10 | <no value> |
| 1451610000000 | 12 | <no value> |
| 1451613600000 | 9 | <no value> |
| 1451617200000 | 13 | <no value> |
| 1451620800000 | 11 | 9.410829834119513 |
| 1451624400000 | 14 | 13.134062139661907 |
| 1451628000000 | <no value> | 10.308574238130804 |
This example adds multiple forecast events.
In this example, forecastLength=2 adds two
forecast events. These events are one step and two steps after
the last input event. The input contains exactly the warm-up
events. As a result, the function produces forecasts but no
predictions on input events.
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=2, forecastLength=2)If event data looks like this:
| @timestamp | value |
|---|---|
| 1451606400000 | 10 |
| 1451610000000 | 12 |
| 1451613600000 | 9 |
| 1451617200000 | 13 |
it would return:
| @timestamp | value | _prediction |
|---|---|---|
| 1451606400000 | 10 | <no value> |
| 1451610000000 | 12 | <no value> |
| 1451613600000 | 9 | <no value> |
| 1451617200000 | 13 | <no value> |
| 1451620800000 | <no value> | 9.410829834119513 |
| 1451624400000 | <no value> | 12.440609260359615 |
This example models an exact periodic series in
additive
mode.
In this example, the series 9,
5, 1,
5 repeats with cycleLength=4.
The model starts with the following estimates:
Level:
5, the mean of one cycle.Trend:
0.Seasonal offsets:
+4,0,-4, and0.
These estimates fit the series exactly. The query sets the following smoothing constants:
baselineConstant=0andslopeConstant=0: The level and trend keep their initial estimates.seasonalityConstant=1: Each seasonal offset equals the latest observed offset. The series fits exactly, so the offsets stay the same.
The forecast for the next position is 5 + 0 + 4 =
9.
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=4, seasonalityMode="additive", baselineConstant=0, slopeConstant=0, seasonalityConstant=1)If event data looks like this:
| @timestamp | value |
|---|---|
| 1451606400000 | 9 |
| 1451610000000 | 5 |
| 1451613600000 | 1 |
| 1451617200000 | 5 |
| 1451620800000 | 9 |
| 1451624400000 | 5 |
| 1451628000000 | 1 |
| 1451631600000 | 5 |
it would return:
| @timestamp | value | _prediction |
|---|---|---|
| 1451606400000 | 9 | <no value> |
| 1451610000000 | 5 | <no value> |
| 1451613600000 | 1 | <no value> |
| 1451617200000 | 5 | <no value> |
| 1451620800000 | 9 | <no value> |
| 1451624400000 | 5 | <no value> |
| 1451628000000 | 1 | <no value> |
| 1451631600000 | 5 | <no value> |
| 1451635200000 | <no value> | 9 |
All eight input events are warm-up events, so the function
returns them unchanged. The forecast event is one hour after
the last input event (_prediction = 9).
This example shows how the function calculates forecast timestamps.
In this example, the first two events are 2000 milliseconds apart. Later events have different spacing. The function calculates forecast timestamps from the first gap only. As a result, the forecast events are 2000 and 4000 milliseconds after the last input event.
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=2, forecastLength=2)If event data looks like this:
| @timestamp | value |
|---|---|
| 1451606400000 | 10 |
| 1451606402000 | 12 |
| 1451606403000 | 9 |
| 1451606409000 | 13 |
it would return:
| @timestamp | value | _prediction |
|---|---|---|
| 1451606400000 | 10 | <no value> |
| 1451606402000 | 12 | <no value> |
| 1451606403000 | 9 | <no value> |
| 1451606409000 | 13 | <no value> |
| 1451606411000 | <no value> | 9.410829834119513 |
| 1451606413000 | <no value> | 12.440609260359615 |
This example shows that the function removes events without the input field.
In this example, two events lack the value field. The function removes these events. They do not count as steps in the series.
The remaining events contain the values 10,
12, 9, and
13. With these values, the forecast value
is 9.410829834119513.
The first two remaining events are two hours apart. As a result, the forecast event is two hours after the last input event.
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=2)If event data looks like this:
| @timestamp | value | other |
|---|---|---|
| 1451606400000 | 10 | <no value> |
| 1451610000000 | <no value> | foo |
| 1451613600000 | 12 | <no value> |
| 1451617200000 | 9 | <no value> |
| 1451620800000 | <no value> | bar |
| 1451624400000 | 13 | <no value> |
it would return:
| @timestamp | value | _prediction |
|---|---|---|
| 1451606400000 | 10 | <no value> |
| 1451613600000 | 12 | <no value> |
| 1451617200000 | 9 | <no value> |
| 1451624400000 | 13 | <no value> |
| 1451631600000 | <no value> | 9.410829834119513 |
This example shows the result when the input is too short for the warm-up.
In this example, cycleLength=3 requires a warm-up
of 6 events. The input contains only 5 events. As a result,
the function returns the events unchanged. The function adds
no forecast events and reports a warning.
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=3)If event data looks like this:
| @timestamp | value |
|---|---|
| 1451606400000 | 1 |
| 1451610000000 | 2 |
| 1451613600000 | 3 |
| 1451617200000 | 4 |
| 1451620800000 | 5 |
it would return:
| @timestamp | value |
|---|---|
| 1451606400000 | 1 |
| 1451610000000 | 2 |
| 1451613600000 | 3 |
| 1451617200000 | 4 |
| 1451620800000 | 5 |
This example models a constant series in both seasonality modes.
In this example, every value is 10. The
function forecasts the same constant in both seasonality
modes.
Query in
multiplicative
mode:
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=2)
Query in
additive
mode:
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=2, seasonalityMode="additive")If event data looks like this:
| @timestamp | value |
|---|---|
| 1451606400000 | 10 |
| 1451610000000 | 10 |
| 1451613600000 | 10 |
| 1451617200000 | 10 |
both queries would return:
| @timestamp | value | _prediction |
|---|---|---|
| 1451606400000 | 10 | <no value> |
| 1451610000000 | 10 | <no value> |
| 1451613600000 | 10 | <no value> |
| 1451617200000 | 10 | <no value> |
| 1451620800000 | <no value> | 10 |
The output holds the four events unchanged, followed by one
forecast event with _prediction = 10.
This example forecasts values from a persisted aggregation.
In this example, a persisted aggregation with the tag
hourlyRequests stores a
count() result every hour. The query
reads the aggregation with span="1h". This
setting returns one row for each hour.
Each row contains the following fields:
_count: The number of requests in that hour.
@timestamp: The start of that hour.
The rows are evenly spaced, so the query requires no bucketing. The query sets the following parameter values:
cycleLength=24: The model learns a daily pattern.forecastLength=24: The function forecasts the next day.
readPersistedAggregation("hourlyRequests", view="myView", span="1h", timezone="UTC")
| sort(@timestamp, order=asc, limit=max)
| statistics:holtWinters(field=_count, cycleLength=24, forecastLength=24)The output contains the following events, in order:
Warm-up events: The first 48 hours, unchanged.
Input events with a prediction: Each later hour, with the
asfield (_prediction).Forecast events: 24 events, one hour apart, after the last hour.
The series must be continuous (no gaps). A missing hour shortens the series and shifts the cycle. For more information, see Events Without a Numeric Value and Removal of events without the input field.
The function models one series only. If the persisted
aggregation includes groupBy(), each
bucket contains one row for each group. In this case, filter
the data to a single group before you call
statistics:holtWinters().
statistics:holtWinters() Examples
Click next to an example below to get the full details.
Forecast Values With A Renamed Output Field
Predict and forecast seasonal values in a custom field using the statistics:holtWinters() function
Query
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=2, as=myForecast)Introduction
In this example, the statistics:holtWinters()
function is used to return predictions and a forecast of the number of
escalated support tickets per shift. The
as parameter
renames the output field to myForecast.
The data contains one event for each 12-hour shift. The night shift starts at 20:00 and the day shift starts at 08:00. The day shift consistently has more escalated tickets than the night shift, so the pattern repeats every two events.
Example incoming data might look like this:
| @timestamp | shift | value |
|---|---|---|
| 2026-03-01T20:00:00Z | night | 10 |
| 2026-03-02T08:00:00Z | day | 12 |
| 2026-03-02T20:00:00Z | night | 9 |
| 2026-03-03T08:00:00Z | day | 13 |
| 2026-03-03T20:00:00Z | night | 11 |
| 2026-03-04T08:00:00Z | day | 14 |
Step-by-Step
Starting with the source repository events.
- logscale
sort(@timestamp, order=asc)Sorts the events by the @timestamp field in ascending order, so that the oldest event comes first.
Sorting is required, because
statistics:holtWinters()processes events in the order that it receives them and treats each event as one step in the series.As
statistics:holtWinters()is an aggregate function, it must be placed after another aggregate function, such assort(),bucket(), orgroupBy().Note that
sort()returns a maximum of200events by default. For longer series, set thelimitparameter, for example, tomax. - logscale
| statistics:holtWinters(field=value, cycleLength=2, as=myForecast)Applies Holt-Winters triple exponential smoothing to the values in the value field and returns the predictions and the forecast in a new field named myForecast.
The function uses the following parameters:
The
fieldparameter specifies the input field with the values to model, in this example value. The function removes events with a missing or non-numeric value in this field.The
cycleLengthparameter specifies the number of events in one cycle. The value2matches the alternating night and day shifts. The value counts events, not time units.The
asparameter renames the output field to myForecast. If the parameter is not specified,statistics:holtWinters()returns the values in a field named _prediction.
As no other parameters are specified,
statistics:holtWinters()uses the following default values:baselineConstant(alpha) is0.3,slopeConstant(beta) is0.1, andseasonalityConstant(gamma) is0.1.forecastLengthis1, so the function adds one forecast event.seasonalityModeismultiplicative, which suits values that remain well above0.
The
statistics:holtWinters()function first uses 2 ×cycleLengthevents, in this example four events, as a warm-up to learn the seasonal pattern. It then adds a prediction to each later input event and finally adds the forecast event after the last input event. Event Result set.
Summary and Results
The query is used to model the number of escalated support tickets per shift, to return a prediction for each shift after the warm-up, and to forecast the number of tickets for the next shift.
This query is useful, for example, to plan staffing for upcoming shifts, or to detect shifts where the actual number of escalated tickets differs significantly from the predicted number.
Sample output from the incoming example data:
| shift | value | myForecast | Â |
|---|---|---|---|
| 2026-03-01T20:00:00Z | night | 10 | <no value> |
| 2026-03-02T08:00:00Z | day | 12 | <no value> |
| 2026-03-02T20:00:00Z | night | 9 | <no value> |
| 2026-03-03T08:00:00Z | day | 13 | <no value> |
| 2026-03-03T20:00:00Z | night | 11 | 9.410829834119513 |
| 2026-03-04T08:00:00Z | day | 14 | 13.134062139661907 |
| 2026-03-04T20:00:00Z | <no value> | <no value> | 10.308574238130804 |
Note that the first four events are warm-up events without the myForecast field, and that the last event is a forecast event that contains only the myForecast and @timestamp fields. The forecast timestamp is 12 hours after the last input event, based on the gap between the first two events.
Also note that the model counts events, not time, so the data must contain exactly one event for each shift. A large difference between the value field and the myForecast field indicates an unusual event.