Skip to content

Commit df853c4

Browse files
authored
Add a MovingFunction pipeline aggregation, deprecate MovingAvg agg (#29594)
This pipeline aggregation gives the user the ability to script functions that "move" across a window of data, instead of single data points. It is the scripted version of MovingAvg pipeline agg. Through custom script contexts, we expose a number of convenience methods: - MovingFunctions.max() - MovingFunctions.min() - MovingFunctions.sum() - MovingFunctions.unweightedAvg() - MovingFunctions.linearWeightedAvg() - MovingFunctions.ewma() - MovingFunctions.holt() - MovingFunctions.holtWinters() - MovingFunctions.stdDev() The user can also define any arbitrary logic via their own scripting, or combine with the above methods.
1 parent fa43aac commit df853c4

File tree

31 files changed

+2876
-177
lines changed

31 files changed

+2876
-177
lines changed

docs/reference/aggregations/pipeline.asciidoc

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ POST /_search
7272
}
7373
--------------------------------------------------
7474
// CONSOLE
75+
// TEST[warning:The moving_avg aggregation has been deprecated in favor of the moving_fn aggregation.]
7576
<1> The metric is called `"the_sum"`
7677
<2> The `buckets_path` refers to the metric via a relative path `"the_sum"`
7778

@@ -136,6 +137,7 @@ POST /_search
136137
}
137138
--------------------------------------------------
138139
// CONSOLE
140+
// TEST[warning:The moving_avg aggregation has been deprecated in favor of the moving_fn aggregation.]
139141
<1> By using `_count` instead of a metric name, we can calculate the moving average of document counts in the histogram
140142

141143
The `buckets_path` can also use `"_bucket_count"` and path to a multi-bucket aggregation to use the number of buckets
@@ -231,6 +233,7 @@ include::pipeline/stats-bucket-aggregation.asciidoc[]
231233
include::pipeline/extended-stats-bucket-aggregation.asciidoc[]
232234
include::pipeline/percentiles-bucket-aggregation.asciidoc[]
233235
include::pipeline/movavg-aggregation.asciidoc[]
236+
include::pipeline/movfn-aggregation.asciidoc[]
234237
include::pipeline/cumulative-sum-aggregation.asciidoc[]
235238
include::pipeline/bucket-script-aggregation.asciidoc[]
236239
include::pipeline/bucket-selector-aggregation.asciidoc[]

docs/reference/aggregations/pipeline/movavg-aggregation.asciidoc

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
[[search-aggregations-pipeline-movavg-aggregation]]
22
=== Moving Average Aggregation
33

4+
deprecated[6.4.0, The Moving Average aggregation has been deprecated in favor of the more general
5+
<<search-aggregations-pipeline-movfn-aggregation,Moving Function Aggregation>>. The new Moving Function aggregation provides
6+
all the same functionality as the Moving Average aggregation, but also provides more flexibility.]
7+
48
Given an ordered series of data, the Moving Average aggregation will slide a window across the data and emit the average
59
value of that window. For example, given the data `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]`, we can calculate a simple moving
610
average with windows size of `5` as follows:
@@ -74,6 +78,7 @@ POST /_search
7478
--------------------------------------------------
7579
// CONSOLE
7680
// TEST[setup:sales]
81+
// TEST[warning:The moving_avg aggregation has been deprecated in favor of the moving_fn aggregation.]
7782

7883
<1> A `date_histogram` named "my_date_histo" is constructed on the "timestamp" field, with one-day intervals
7984
<2> A `sum` metric is used to calculate the sum of a field. This could be any metric (sum, min, max, etc)
@@ -180,6 +185,7 @@ POST /_search
180185
--------------------------------------------------
181186
// CONSOLE
182187
// TEST[setup:sales]
188+
// TEST[warning:The moving_avg aggregation has been deprecated in favor of the moving_fn aggregation.]
183189

184190
A `simple` model has no special settings to configure
185191

@@ -233,6 +239,7 @@ POST /_search
233239
--------------------------------------------------
234240
// CONSOLE
235241
// TEST[setup:sales]
242+
// TEST[warning:The moving_avg aggregation has been deprecated in favor of the moving_fn aggregation.]
236243

237244
A `linear` model has no special settings to configure
238245

@@ -295,7 +302,7 @@ POST /_search
295302
--------------------------------------------------
296303
// CONSOLE
297304
// TEST[setup:sales]
298-
305+
// TEST[warning:The moving_avg aggregation has been deprecated in favor of the moving_fn aggregation.]
299306

300307
[[single_0.2alpha]]
301308
.EWMA with window of size 10, alpha = 0.2
@@ -355,6 +362,7 @@ POST /_search
355362
--------------------------------------------------
356363
// CONSOLE
357364
// TEST[setup:sales]
365+
// TEST[warning:The moving_avg aggregation has been deprecated in favor of the moving_fn aggregation.]
358366

359367
In practice, the `alpha` value behaves very similarly in `holt` as `ewma`: small values produce more smoothing
360368
and more lag, while larger values produce closer tracking and less lag. The value of `beta` is often difficult
@@ -446,7 +454,7 @@ POST /_search
446454
--------------------------------------------------
447455
// CONSOLE
448456
// TEST[setup:sales]
449-
457+
// TEST[warning:The moving_avg aggregation has been deprecated in favor of the moving_fn aggregation.]
450458

451459
[[holt_winters_add]]
452460
.Holt-Winters moving average with window of size 120, alpha = 0.5, beta = 0.7, gamma = 0.3, period = 30
@@ -508,6 +516,7 @@ POST /_search
508516
--------------------------------------------------
509517
// CONSOLE
510518
// TEST[setup:sales]
519+
// TEST[warning:The moving_avg aggregation has been deprecated in favor of the moving_fn aggregation.]
511520

512521
==== Prediction
513522

@@ -550,6 +559,7 @@ POST /_search
550559
--------------------------------------------------
551560
// CONSOLE
552561
// TEST[setup:sales]
562+
// TEST[warning:The moving_avg aggregation has been deprecated in favor of the moving_fn aggregation.]
553563

554564
The `simple`, `linear` and `ewma` models all produce "flat" predictions: they essentially converge on the mean
555565
of the last value in the series, producing a flat:
@@ -631,6 +641,7 @@ POST /_search
631641
--------------------------------------------------
632642
// CONSOLE
633643
// TEST[setup:sales]
644+
// TEST[warning:The moving_avg aggregation has been deprecated in favor of the moving_fn aggregation.]
634645

635646
<1> Minimization is enabled with the `minimize` parameter
636647

0 commit comments

Comments
 (0)