Skip to content

Commit 6e121ef

Browse files
Mpdreamzrusscam
authored andcommitted
Add shift option to moving_avg aggregation (#4140)
Addresses elastic/elasticsearch#44360
1 parent 0348bf1 commit 6e121ef

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Nest/Aggregations/Pipeline/MovingFunction/MovingFunctionAggregation.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public interface IMovingFunctionAggregation : IPipelineAggregation
1212

1313
[DataMember(Name ="window")]
1414
int? Window { get; set; }
15+
16+
[DataMember(Name ="shift")]
17+
int? Shift { get; set; }
1518
}
1619

1720
public class MovingFunctionAggregation
@@ -26,6 +29,8 @@ public MovingFunctionAggregation(string name, SingleBucketsPath bucketsPath)
2629

2730
public int? Window { get; set; }
2831

32+
public int? Shift { get; set; }
33+
2934
internal override void WrapInContainer(AggregationContainer c) => c.MovingFunction = this;
3035
}
3136

@@ -35,9 +40,13 @@ public class MovingFunctionAggregationDescriptor
3540
{
3641
string IMovingFunctionAggregation.Script { get; set; }
3742
int? IMovingFunctionAggregation.Window { get; set; }
43+
int? IMovingFunctionAggregation.Shift { get; set; }
3844

3945
public MovingFunctionAggregationDescriptor Window(int? windowSize) => Assign(windowSize, (a, v) => a.Window = v);
4046

4147
public MovingFunctionAggregationDescriptor Script(string script) => Assign(script, (a, v) => a.Script = v);
48+
49+
public MovingFunctionAggregationDescriptor Shift(int? shift) => Assign(shift, (a, v) => a.Shift = v);
50+
4251
}
4352
}

src/Tests/Tests/Aggregations/Pipeline/MovingFunction/MovingFunctionAggregationUsageTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Tests.Aggregations.Pipeline.MovingFunction
2121
*
2222
* Be sure to read the Elasticsearch documentation on {ref_current}/search-aggregations-pipeline-movfn-aggregation.html[Moving Function Aggregation]
2323
*/
24-
[SkipVersion("<6.4.0", "Introduced in Elasticsearch 6.4.0+")]
24+
[SkipVersion("<7.4.0", "Shift option introduced in 7.4.0+")]
2525
public class MovingFunctionAggregationUsageTests : AggregationUsageTestBase
2626
{
2727
public MovingFunctionAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
@@ -50,6 +50,7 @@ public MovingFunctionAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsag
5050
{
5151
buckets_path = "commits",
5252
window = 30,
53+
shift = 0,
5354
script = "MovingFunctions.unweightedAvg(values)"
5455
}
5556
}
@@ -69,6 +70,7 @@ public MovingFunctionAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsag
6970
.MovingFunction("commits_moving_avg", mv => mv
7071
.BucketsPath("commits")
7172
.Window(30)
73+
.Shift(0)
7274
.Script("MovingFunctions.unweightedAvg(values)")
7375
)
7476
)
@@ -84,6 +86,7 @@ public MovingFunctionAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsag
8486
&& new MovingFunctionAggregation("commits_moving_avg", "commits")
8587
{
8688
Window = 30,
89+
Shift = 0,
8790
Script = "MovingFunctions.unweightedAvg(values)"
8891
}
8992
};

0 commit comments

Comments
 (0)