Skip to content

Commit 802c570

Browse files
authored
Force selection of calendar or fixed intervals in date histo aggregations (#3988)
Implements elastic/elasticsearch#33727
1 parent d4c9cef commit 802c570

23 files changed

+67
-0
lines changed

src/Nest/Aggregations/Bucket/DateHistogram/DateHistogramAggregation.cs

+21
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,16 @@ public interface IDateHistogramAggregation : IBucketAggregation
1919
[DataMember(Name ="format")]
2020
string Format { get; set; }
2121

22+
[Obsolete("Deprecated in version 7.2.0, use CalendarInterval or FixedInterval instead")]
2223
[DataMember(Name ="interval")]
2324
Union<DateInterval, Time> Interval { get; set; }
2425

26+
[DataMember(Name ="calendar_interval")]
27+
Union<DateInterval, Time> CalendarInterval { get; set; }
28+
29+
[DataMember(Name ="fixed_interval")]
30+
Union<DateInterval, Time> FixedInterval { get; set; }
31+
2532
[DataMember(Name ="min_doc_count")]
2633
int? MinimumDocumentCount { get; set; }
2734

@@ -65,7 +72,11 @@ public string Format
6572
set => _format = value;
6673
}
6774

75+
76+
[Obsolete("Deprecated in version 7.2.0, use CalendarInterval or FixedInterval instead")]
6877
public Union<DateInterval, Time> Interval { get; set; }
78+
public Union<DateInterval, Time> CalendarInterval { get; set; }
79+
public Union<DateInterval, Time> FixedInterval { get; set; }
6980

7081
public int? MinimumDocumentCount { get; set; }
7182
public DateTime? Missing { get; set; }
@@ -99,7 +110,10 @@ string IDateHistogramAggregation.Format
99110
set => _format = value;
100111
}
101112

113+
[Obsolete("Deprecated in version 7.2.0, use CalendarInterval or FixedInterval instead")]
102114
Union<DateInterval, Time> IDateHistogramAggregation.Interval { get; set; }
115+
Union<DateInterval, Time> IDateHistogramAggregation.CalendarInterval { get; set; }
116+
Union<DateInterval, Time> IDateHistogramAggregation.FixedInterval { get; set; }
103117

104118
int? IDateHistogramAggregation.MinimumDocumentCount { get; set; }
105119

@@ -124,11 +138,18 @@ string IDateHistogramAggregation.Format
124138
public DateHistogramAggregationDescriptor<T> Script(Func<ScriptDescriptor, IScript> scriptSelector) =>
125139
Assign(scriptSelector, (a, v) => a.Script = v?.Invoke(new ScriptDescriptor()));
126140

141+
[Obsolete("Deprecated in version 7.2.0, use CalendarInterval or FixedInterval instead")]
127142
public DateHistogramAggregationDescriptor<T> Interval(Time interval) => Assign(interval, (a, v) => a.Interval = v);
128143

144+
[Obsolete("Deprecated in version 7.2.0, use CalendarInterval or FixedInterval instead")]
129145
public DateHistogramAggregationDescriptor<T> Interval(DateInterval interval) =>
130146
Assign(interval, (a, v) => a.Interval = v);
131147

148+
public DateHistogramAggregationDescriptor<T> CalendarInterval(Time interval) => Assign(interval, (a, v) => a.CalendarInterval = v);
149+
public DateHistogramAggregationDescriptor<T> CalendarInterval(DateInterval interval) => Assign(interval, (a, v) => a.CalendarInterval = v);
150+
public DateHistogramAggregationDescriptor<T> FixedInterval(Time interval) => Assign(interval, (a, v) => a.FixedInterval = v);
151+
public DateHistogramAggregationDescriptor<T> FixedInterval(DateInterval interval) => Assign(interval, (a, v) => a.FixedInterval = v);
152+
132153
public DateHistogramAggregationDescriptor<T> Format(string format) => Assign(format, (a, v) => a.Format = v);
133154

134155
public DateHistogramAggregationDescriptor<T> MinimumDocumentCount(int? minimumDocumentCount) =>

src/Tests/Tests.Reproduce/GithubIssue3673.cs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class GithubIssue3673 : IClusterFixture<ReadOnlyCluster>
1616
[I]
1717
public void DeserializeDateAggregation()
1818
{
19+
#pragma warning disable 612, 618
1920
Action action = () => _cluster.Client.Search<Project>(s => s
2021
.Size(0)
2122
.Aggregations(a => a
@@ -27,6 +28,7 @@ public void DeserializeDateAggregation()
2728
)
2829
)
2930
);
31+
#pragma warning restore 612, 618
3032

3133
action.Should().NotThrow();
3234
}

src/Tests/Tests/Aggregations/Bucket/DateHistogram/DateHistogramAggregationUsageTests.cs

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public DateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage
6464
}
6565
};
6666

67+
#pragma warning disable 618, 612
6768
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
6869
.DateHistogram("projects_started_per_month", date => date
6970
.Field(p => p.StartedOn)
@@ -106,6 +107,7 @@ public DateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage
106107
}
107108
}
108109
};
110+
#pragma warning restore 618, 612
109111

110112
protected override void ExpectResponse(ISearchResponse<Project> response)
111113
{
@@ -160,6 +162,7 @@ public DateHistogramAggregationNoSubAggregationsUsageTests(ReadOnlyCluster i, En
160162
}
161163
};
162164

165+
#pragma warning disable 618, 612
163166
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
164167
.DateHistogram("projects_started_per_month", date => date
165168
.Field(p => p.StartedOn)
@@ -186,6 +189,7 @@ public DateHistogramAggregationNoSubAggregationsUsageTests(ReadOnlyCluster i, En
186189
Order = HistogramOrder.CountAscending,
187190
Missing = FixedDate
188191
};
192+
#pragma warning restore 618, 612
189193

190194
protected override void ExpectResponse(ISearchResponse<Project> response)
191195
{

src/Tests/Tests/Aggregations/Pipeline/AverageBucket/AverageBucketAggregationUsageTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public AverageBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
4242
}
4343
};
4444

45+
#pragma warning disable 618, 612
4546
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
4647
.DateHistogram("projects_started_per_month", dh => dh
4748
.Field(p => p.StartedOn)
@@ -68,6 +69,7 @@ public AverageBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
6869
{
6970
GapPolicy = GapPolicy.InsertZeros
7071
};
72+
#pragma warning restore 618, 612
7173

7274
protected override void ExpectResponse(ISearchResponse<Project> response)
7375
{

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

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public BucketScriptAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
7272
}
7373
};
7474

75+
#pragma warning disable 618, 612
7576
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
7677
.DateHistogram("projects_started_per_month", dh => dh
7778
.Field(p => p.StartedOn)
@@ -125,6 +126,7 @@ public BucketScriptAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
125126
Script = new InlineScript("params.stableCommits / params.totalCommits * 100")
126127
}
127128
};
129+
#pragma warning restore 618, 612
128130

129131
protected override void ExpectResponse(ISearchResponse<Project> response)
130132
{

src/Tests/Tests/Aggregations/Pipeline/BucketSelector/BucketSelectorAggregationUsageTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public BucketSelectorAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsag
4848
}
4949
};
5050

51+
#pragma warning disable 618, 612
5152
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
5253
.DateHistogram("projects_started_per_month", dh => dh
5354
.Field(p => p.StartedOn)
@@ -80,6 +81,7 @@ public BucketSelectorAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsag
8081
Script = new InlineScript("params.totalCommits >= 500")
8182
}
8283
};
84+
#pragma warning restore 618, 612
8385

8486
protected override void ExpectResponse(ISearchResponse<Project> response)
8587
{

src/Tests/Tests/Aggregations/Pipeline/BucketSort/BucketSortAggregationUsageTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public BucketSortAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
5050
}
5151
};
5252

53+
#pragma warning disable 618, 612
5354
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
5455
.DateHistogram("projects_started_per_month", dh => dh
5556
.Field(p => p.StartedOn)
@@ -87,6 +88,7 @@ public BucketSortAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
8788
GapPolicy = GapPolicy.InsertZeros
8889
}
8990
};
91+
#pragma warning restore 618, 612
9092

9193
protected override void ExpectResponse(ISearchResponse<Project> response)
9294
{

src/Tests/Tests/Aggregations/Pipeline/CumulativeSum/CumulativeSumAggregationUsageTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public CumulativeSumAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
4141
}
4242
};
4343

44+
#pragma warning disable 618, 612
4445
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
4546
.DateHistogram("projects_started_per_month", dh => dh
4647
.Field(p => p.StartedOn)
@@ -64,6 +65,7 @@ public CumulativeSumAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
6465
new SumAggregation("commits", "numberOfCommits") &&
6566
new CumulativeSumAggregation("cumulative_commits", "commits")
6667
};
68+
#pragma warning restore 618
6769

6870
protected override void ExpectResponse(ISearchResponse<Project> response)
6971
{

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

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public DerivativeAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
4242
}
4343
};
4444

45+
#pragma warning disable 618, 612
4546
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
4647
.DateHistogram("projects_started_per_month", dh => dh
4748
.Field(p => p.StartedOn)
@@ -65,6 +66,7 @@ public DerivativeAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
6566
new SumAggregation("commits", "numberOfCommits") &&
6667
new DerivativeAggregation("commits_derivative", "commits")
6768
};
69+
#pragma warning restore 618, 612
6870

6971
protected override void ExpectResponse(ISearchResponse<Project> response)
7072
{

src/Tests/Tests/Aggregations/Pipeline/ExtendedStatsBucket/ExtendedStatsBucketAggregationUsageTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public ExtendedStatsBucketAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
4242
}
4343
};
4444

45+
#pragma warning disable 618, 612
4546
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
4647
.DateHistogram("projects_started_per_month", dh => dh
4748
.Field(p => p.StartedOn)
@@ -68,6 +69,7 @@ public ExtendedStatsBucketAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
6869
{
6970
Sigma = 2.0
7071
};
72+
#pragma warning restore 618, 612
7173

7274
protected override void ExpectResponse(ISearchResponse<Project> response)
7375
{

src/Tests/Tests/Aggregations/Pipeline/MaxBucket/MaxBucketAggregationUsageTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public MaxBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage usa
4141
}
4242
};
4343

44+
#pragma warning disable 618, 612
4445
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
4546
.DateHistogram("projects_started_per_month", dh => dh
4647
.Field(p => p.StartedOn)
@@ -63,6 +64,7 @@ public MaxBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage usa
6364
Aggregations = new SumAggregation("commits", "numberOfCommits")
6465
}
6566
&& new MaxBucketAggregation("max_commits_per_month", "projects_started_per_month>commits");
67+
#pragma warning restore 618, 612
6668

6769
protected override void ExpectResponse(ISearchResponse<Project> response)
6870
{

src/Tests/Tests/Aggregations/Pipeline/MinBucket/MinBucketAggregationUsageTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public MinBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage usa
4141
}
4242
};
4343

44+
#pragma warning disable 618, 612
4445
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
4546
.DateHistogram("projects_started_per_month", dh => dh
4647
.Field(p => p.StartedOn)
@@ -63,6 +64,7 @@ public MinBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage usa
6364
Aggregations = new SumAggregation("commits", "numberOfCommits")
6465
}
6566
&& new MinBucketAggregation("min_commits_per_month", "projects_started_per_month>commits");
67+
#pragma warning restore 618, 612
6668

6769
protected override void ExpectResponse(ISearchResponse<Project> response)
6870
{

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

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public MovingAverageEwmaAggregationUsageTests(ReadOnlyCluster cluster, EndpointU
4949
}
5050
};
5151

52+
#pragma warning disable 618, 612
5253
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
5354
.DateHistogram("projects_started_per_month", dh => dh
5455
.Field(p => p.StartedOn)
@@ -83,6 +84,7 @@ public MovingAverageEwmaAggregationUsageTests(ReadOnlyCluster cluster, EndpointU
8384
}
8485
}
8586
};
87+
#pragma warning restore 618, 612
8688

8789
protected override void ExpectResponse(ISearchResponse<Project> response)
8890
{

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

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public MovingAverageHoltLinearAggregationUsageTests(ReadOnlyCluster cluster, End
5050
}
5151
};
5252

53+
#pragma warning disable 618, 612
5354
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
5455
.DateHistogram("projects_started_per_month", dh => dh
5556
.Field(p => p.StartedOn)
@@ -84,6 +85,7 @@ public MovingAverageHoltLinearAggregationUsageTests(ReadOnlyCluster cluster, End
8485
}
8586
}
8687
};
88+
#pragma warning restore 618, 612
8789

8890
protected override void ExpectResponse(ISearchResponse<Project> response)
8991
{

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

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public MovingAverageHoltWintersUsageTests(ReadOnlyCluster cluster, EndpointUsage
5454
}
5555
};
5656

57+
#pragma warning disable 618, 612
5758
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
5859
.DateHistogram("projects_started_per_month", dh => dh
5960
.Field(p => p.StartedOn)
@@ -100,6 +101,7 @@ public MovingAverageHoltWintersUsageTests(ReadOnlyCluster cluster, EndpointUsage
100101
}
101102
}
102103
};
104+
#pragma warning restore 618, 612
103105

104106
protected override void ExpectResponse(ISearchResponse<Project> response)
105107
{

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

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public MovingAverageLinearAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
4747
}
4848
};
4949

50+
#pragma warning disable 618, 612
5051
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
5152
.DateHistogram("projects_started_per_month", dh => dh
5253
.Field(p => p.StartedOn)
@@ -78,6 +79,7 @@ public MovingAverageLinearAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
7879
Model = new LinearModel()
7980
}
8081
};
82+
#pragma warning restore 618, 612
8183

8284
protected override void ExpectResponse(ISearchResponse<Project> response)
8385
{

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

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
4848
}
4949
};
5050

51+
#pragma warning disable 618, 612
5152
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
5253
.DateHistogram("projects_started_per_month", dh => dh
5354
.Field(p => p.StartedOn)
@@ -81,6 +82,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
8182
Model = new SimpleModel()
8283
}
8384
};
85+
#pragma warning restore 618, 612
8486

8587
protected override void ExpectResponse(ISearchResponse<Project> response)
8688
{

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

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public MovingFunctionAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsag
5757
}
5858
};
5959

60+
#pragma warning disable 618, 612
6061
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
6162
.DateHistogram("projects_started_per_month", dh => dh
6263
.Field(p => p.StartedOn)
@@ -86,6 +87,7 @@ public MovingFunctionAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsag
8687
Script = "MovingFunctions.unweightedAvg(values)"
8788
}
8889
};
90+
#pragma warning restore 618, 612
8991

9092
protected override void ExpectResponse(ISearchResponse<Project> response)
9193
{

src/Tests/Tests/Aggregations/Pipeline/PercentilesBucket/PercentilesBucketAggregationUsageTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public PercentilesBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointU
4242
}
4343
};
4444

45+
#pragma warning disable 618, 612
4546
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
4647
.DateHistogram("projects_started_per_month", dh => dh
4748
.Field(p => p.StartedOn)
@@ -68,6 +69,7 @@ public PercentilesBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointU
6869
{
6970
Percents = new[] { 95, 99, 99.9 }
7071
};
72+
#pragma warning restore 618, 612
7173

7274
protected override void ExpectResponse(ISearchResponse<Project> response)
7375
{

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

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public SerialDifferencingAggregationUsageTests(ReadOnlyCluster cluster, Endpoint
4242
}
4343
};
4444

45+
#pragma warning disable 618, 612
4546
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
4647
.DateHistogram("projects_started_per_month", dh => dh
4748
.Field(p => p.StartedOn)
@@ -69,6 +70,7 @@ public SerialDifferencingAggregationUsageTests(ReadOnlyCluster cluster, Endpoint
6970
Lag = 2
7071
}
7172
};
73+
#pragma warning restore 618, 612
7274

7375
protected override void ExpectResponse(ISearchResponse<Project> response)
7476
{

src/Tests/Tests/Aggregations/Pipeline/StatsBucket/StatsBucketAggregationUsageTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public StatsBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage u
4141
}
4242
};
4343

44+
#pragma warning disable 618, 612
4445
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
4546
.DateHistogram("projects_started_per_month", dh => dh
4647
.Field(p => p.StartedOn)
@@ -63,6 +64,7 @@ public StatsBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage u
6364
Aggregations = new SumAggregation("commits", "numberOfCommits")
6465
}
6566
&& new StatsBucketAggregation("stats_commits_per_month", "projects_started_per_month>commits");
67+
#pragma warning restore 618, 612
6668

6769
protected override void ExpectResponse(ISearchResponse<Project> response)
6870
{

0 commit comments

Comments
 (0)