Skip to content

Commit 62fbfe9

Browse files
committed
Fix aggs integration tests where buckets can be empty (#4169)
This commit fixes integration tests for aggregations that use a date_histogram aggregation, where a bucker may have no documents with a specific seed value. For example, build.bat seed:41075 integrate 7.4.0 "readonly" (cherry picked from commit b63a4f3)
1 parent 6c279e8 commit 62fbfe9

File tree

7 files changed

+26
-5
lines changed

7 files changed

+26
-5
lines changed

src/Tests/Tests/Aggregations/Pipeline/BucketScript/BucketScriptAggregationUsageTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public BucketScriptAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
2020
{
2121
field = "startedOn",
2222
interval = "month",
23+
min_doc_count = 1
2324
},
2425
aggs = new
2526
{
@@ -77,6 +78,7 @@ public BucketScriptAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
7778
.DateHistogram("projects_started_per_month", dh => dh
7879
.Field(p => p.StartedOn)
7980
.Interval(DateInterval.Month)
81+
.MinimumDocumentCount(1)
8082
.Aggregations(aa => aa
8183
.Sum("commits", sm => sm
8284
.Field(p => p.NumberOfCommits)
@@ -106,6 +108,7 @@ public BucketScriptAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
106108
{
107109
Field = "startedOn",
108110
Interval = DateInterval.Month,
111+
MinimumDocumentCount = 1,
109112
Aggregations =
110113
new SumAggregation("commits", "numberOfCommits") &&
111114
new FilterAggregation("stable_state")

src/Tests/Tests/Aggregations/Pipeline/Derivative/DerivativeAggregationUsageTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public DerivativeAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
2121
{
2222
field = "startedOn",
2323
interval = "month",
24+
min_doc_count = 1
2425
},
2526
aggs = new
2627
{
@@ -47,6 +48,7 @@ public DerivativeAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
4748
.DateHistogram("projects_started_per_month", dh => dh
4849
.Field(p => p.StartedOn)
4950
.Interval(DateInterval.Month)
51+
.MinimumDocumentCount(1)
5052
.Aggregations(aa => aa
5153
.Sum("commits", sm => sm
5254
.Field(p => p.NumberOfCommits)
@@ -62,6 +64,7 @@ public DerivativeAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
6264
{
6365
Field = "startedOn",
6466
Interval = DateInterval.Month,
67+
MinimumDocumentCount = 1,
6568
Aggregations =
6669
new SumAggregation("commits", "numberOfCommits") &&
6770
new DerivativeAggregation("commits_derivative", "commits")

src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageEwmaAggregationUsageTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public MovingAverageEwmaAggregationUsageTests(ReadOnlyCluster cluster, EndpointU
4141
{
4242
field = "startedOn",
4343
interval = "month",
44+
min_doc_count = 1
4445
},
4546
aggs = new
4647
{
@@ -72,6 +73,7 @@ public MovingAverageEwmaAggregationUsageTests(ReadOnlyCluster cluster, EndpointU
7273
.DateHistogram("projects_started_per_month", dh => dh
7374
.Field(p => p.StartedOn)
7475
.Interval(DateInterval.Month)
76+
.MinimumDocumentCount(1)
7577
.Aggregations(aa => aa
7678
.Sum("commits", sm => sm
7779
.Field(p => p.NumberOfCommits)
@@ -92,6 +94,7 @@ public MovingAverageEwmaAggregationUsageTests(ReadOnlyCluster cluster, EndpointU
9294
{
9395
Field = "startedOn",
9496
Interval = DateInterval.Month,
97+
MinimumDocumentCount = 1,
9598
Aggregations =
9699
new SumAggregation("commits", "numberOfCommits")
97100
&& new MovingAverageAggregation("commits_moving_avg", "commits")

src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageHoltLinearAggregationUsageTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public MovingAverageHoltLinearAggregationUsageTests(ReadOnlyCluster cluster, End
4040
date_histogram = new
4141
{
4242
field = "startedOn",
43-
interval = "month"
43+
interval = "month",
44+
min_doc_count = 1
4445
},
4546
aggs = new
4647
{
@@ -73,6 +74,7 @@ public MovingAverageHoltLinearAggregationUsageTests(ReadOnlyCluster cluster, End
7374
.DateHistogram("projects_started_per_month", dh => dh
7475
.Field(p => p.StartedOn)
7576
.Interval(DateInterval.Month)
77+
.MinimumDocumentCount(1)
7678
.Aggregations(aa => aa
7779
.Sum("commits", sm => sm.Field(p => p.NumberOfCommits))
7880
.MovingAverage("commits_moving_avg", mv => mv
@@ -92,6 +94,7 @@ public MovingAverageHoltLinearAggregationUsageTests(ReadOnlyCluster cluster, End
9294
{
9395
Field = "startedOn",
9496
Interval = DateInterval.Month,
97+
MinimumDocumentCount = 1,
9598
Aggregations =
9699
new SumAggregation("commits", "numberOfCommits")
97100
&& new MovingAverageAggregation("commits_moving_avg", "commits")

src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageHoltWintersAggregationUsageTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public MovingAverageHoltWintersUsageTests(ReadOnlyCluster cluster, EndpointUsage
3939
date_histogram = new
4040
{
4141
field = "startedOn",
42-
interval = "month"
42+
interval = "month",
43+
min_doc_count = 1
4344
},
4445
aggs = new
4546
{
@@ -77,6 +78,7 @@ public MovingAverageHoltWintersUsageTests(ReadOnlyCluster cluster, EndpointUsage
7778
.DateHistogram("projects_started_per_month", dh => dh
7879
.Field(p => p.StartedOn)
7980
.Interval(DateInterval.Month)
81+
.MinimumDocumentCount(1)
8082
.Aggregations(aa => aa
8183
.Sum("commits", sm => sm
8284
.Field(p => p.NumberOfCommits)
@@ -103,6 +105,7 @@ public MovingAverageHoltWintersUsageTests(ReadOnlyCluster cluster, EndpointUsage
103105
{
104106
Field = "startedOn",
105107
Interval = DateInterval.Month,
108+
MinimumDocumentCount = 1,
106109
Aggregations =
107110
new SumAggregation("commits", "numberOfCommits")
108111
&& new MovingAverageAggregation("commits_moving_avg", "commits")
@@ -142,7 +145,7 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
142145
var movingAverage = item.MovingAverage("commits_moving_avg");
143146

144147
// Moving Average specifies a window of 4 so
145-
// moving average values should exist from 5th bucketr onwards
148+
// moving average values should exist from 5th bucket onwards
146149
if (bucketCount <= 4)
147150
movingAverage.Should().BeNull();
148151
else

src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageSimpleAggregationUsageTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
4040
date_histogram = new
4141
{
4242
field = "startedOn",
43-
interval = "month",
43+
interval = "month"
4444
},
4545
aggs = new
4646
{
@@ -59,6 +59,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
5959
model = "simple",
6060
window = 30,
6161
predict = 10,
62+
gap_policy = "insert_zeros",
6263
settings = new { }
6364
}
6465
}
@@ -79,6 +80,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
7980
.BucketsPath("commits")
8081
.Window(30)
8182
.Predict(10)
83+
.GapPolicy(GapPolicy.InsertZeros)
8284
.Model(m => m
8385
.Simple()
8486
)
@@ -97,6 +99,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
9799
{
98100
Window = 30,
99101
Predict = 10,
102+
GapPolicy = GapPolicy.InsertZeros,
100103
Model = new SimpleModel()
101104
}
102105
};

src/Tests/Tests/Aggregations/Pipeline/SerialDifferencing/SerialDifferencingAggregationUsageTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public SerialDifferencingAggregationUsageTests(ReadOnlyCluster cluster, Endpoint
1919
date_histogram = new
2020
{
2121
field = "startedOn",
22-
interval = "month"
22+
interval = "month",
23+
min_doc_count = 1
2324
},
2425
aggs = new
2526
{
@@ -47,6 +48,7 @@ public SerialDifferencingAggregationUsageTests(ReadOnlyCluster cluster, Endpoint
4748
.DateHistogram("projects_started_per_month", dh => dh
4849
.Field(p => p.StartedOn)
4950
.Interval(DateInterval.Month)
51+
.MinimumDocumentCount(1)
5052
.Aggregations(aa => aa
5153
.Sum("commits", sm => sm
5254
.Field(p => p.NumberOfCommits)
@@ -63,6 +65,7 @@ public SerialDifferencingAggregationUsageTests(ReadOnlyCluster cluster, Endpoint
6365
{
6466
Field = "startedOn",
6567
Interval = DateInterval.Month,
68+
MinimumDocumentCount = 1,
6669
Aggregations =
6770
new SumAggregation("commits", "numberOfCommits")
6871
&& new SerialDifferencingAggregation("second_difference", "commits")

0 commit comments

Comments
 (0)