Skip to content

Add shift option to moving_avg aggregation #4140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public interface IMovingFunctionAggregation : IPipelineAggregation

[DataMember(Name ="window")]
int? Window { get; set; }

[DataMember(Name ="shift")]
int? Shift { get; set; }
}

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

public int? Window { get; set; }

public int? Shift { get; set; }

internal override void WrapInContainer(AggregationContainer c) => c.MovingFunction = this;
}

Expand All @@ -35,9 +40,13 @@ public class MovingFunctionAggregationDescriptor
{
string IMovingFunctionAggregation.Script { get; set; }
int? IMovingFunctionAggregation.Window { get; set; }
int? IMovingFunctionAggregation.Shift { get; set; }

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

public MovingFunctionAggregationDescriptor Script(string script) => Assign(script, (a, v) => a.Script = v);

public MovingFunctionAggregationDescriptor Shift(int? shift) => Assign(shift, (a, v) => a.Shift = v);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Tests.Aggregations.Pipeline.MovingFunction
*
* Be sure to read the Elasticsearch documentation on {ref_current}/search-aggregations-pipeline-movfn-aggregation.html[Moving Function Aggregation]
*/
[SkipVersion("<6.4.0", "Introduced in Elasticsearch 6.4.0+")]
[SkipVersion("<7.4.0", "Shift option introduced in 7.4.0+")]
public class MovingFunctionAggregationUsageTests : AggregationUsageTestBase
{
public MovingFunctionAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
Expand Down Expand Up @@ -50,6 +50,7 @@ public MovingFunctionAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsag
{
buckets_path = "commits",
window = 30,
shift = 0,
script = "MovingFunctions.unweightedAvg(values)"
}
}
Expand All @@ -69,6 +70,7 @@ public MovingFunctionAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsag
.MovingFunction("commits_moving_avg", mv => mv
.BucketsPath("commits")
.Window(30)
.Shift(0)
.Script("MovingFunctions.unweightedAvg(values)")
)
)
Expand All @@ -84,6 +86,7 @@ public MovingFunctionAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsag
&& new MovingFunctionAggregation("commits_moving_avg", "commits")
{
Window = 30,
Shift = 0,
Script = "MovingFunctions.unweightedAvg(values)"
}
};
Expand Down