Skip to content

Commit e324c91

Browse files
authored
Add FixedInterval and CalendarInterval to IDateHistogramCompositeAggregationSource (#4772)
This commit adds FixedInterval and CalendarInterval to IDateHistogramCompositeAggregationSource and deprecates Interval. FixedInterval uses Time type as units must be specified and the largest unit supported is Day. CalendarInterval can specify either a DateInterval or a DateMathTime with a fixed unit of 1. Closes #4695.
1 parent b46893b commit e324c91

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

docs/aggregations/bucket/composite/composite-aggregation-usage.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ a => a
4141
)
4242
.DateHistogram("started", d => d
4343
.Field(f => f.StartedOn)
44-
.Interval(DateInterval.Month)
44+
.CalendarInterval(DateInterval.Month)
4545
)
4646
.Histogram("branch_count", h => h
4747
.Field(f => f.RequiredBranches)
@@ -78,7 +78,7 @@ new CompositeAggregation("my_buckets")
7878
new DateHistogramCompositeAggregationSource("started")
7979
{
8080
Field = Field<Project>(f => f.StartedOn),
81-
Interval = DateInterval.Month
81+
CalendarInterval = DateInterval.Month
8282
},
8383
new HistogramCompositeAggregationSource("branch_count")
8484
{
@@ -120,7 +120,7 @@ new CompositeAggregation("my_buckets")
120120
"started": {
121121
"date_histogram": {
122122
"field": "startedOn",
123-
"interval": "month"
123+
"calendar_interval": "month"
124124
}
125125
}
126126
},

src/Nest/Aggregations/Bucket/Composite/DateHistogramCompositeAggregationSource.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5+
using System;
56
using System.Runtime.Serialization;
67

78
namespace Nest
@@ -21,11 +22,24 @@ public interface IDateHistogramCompositeAggregationSource : ICompositeAggregatio
2122
string Format { get; set; }
2223

2324
/// <summary>
24-
/// The interval to use when bucketing documents
25+
/// The interval to use when bucketing documents
2526
/// </summary>
2627
[DataMember(Name ="interval")]
28+
[Obsolete("Use FixedInterval or CalendarInterval")]
2729
Union<DateInterval?, Time> Interval { get; set; }
2830

31+
/// <summary>
32+
/// The calendar interval to use when bucketing documents
33+
/// </summary>
34+
[DataMember(Name ="calendar_interval")]
35+
public Union<DateInterval?, DateMathTime> CalendarInterval { get; set; }
36+
37+
/// <summary>
38+
/// The fixed interval to use when bucketing documents
39+
/// </summary>
40+
[DataMember(Name ="fixed_interval")]
41+
public Time FixedInterval { get; set; }
42+
2943
/// <summary>
3044
/// Used to indicate that bucketing should use a different time zone.
3145
/// Time zones may either be specified as an ISO 8601 UTC offset (e.g. +01:00 or -08:00)
@@ -44,8 +58,15 @@ public DateHistogramCompositeAggregationSource(string name) : base(name) { }
4458
public string Format { get; set; }
4559

4660
/// <inheritdoc />
61+
[Obsolete("Use FixedInterval or CalendarInterval")]
4762
public Union<DateInterval?, Time> Interval { get; set; }
4863

64+
/// <inheritdoc />
65+
public Union<DateInterval?, DateMathTime> CalendarInterval { get; set; }
66+
67+
/// <inheritdoc />
68+
public Time FixedInterval { get; set; }
69+
4970
/// <inheritdoc />
5071
public string TimeZone { get; set; }
5172

@@ -62,16 +83,32 @@ public DateHistogramCompositeAggregationSourceDescriptor(string name) : base(nam
6283

6384
string IDateHistogramCompositeAggregationSource.Format { get; set; }
6485
Union<DateInterval?, Time> IDateHistogramCompositeAggregationSource.Interval { get; set; }
86+
Union<DateInterval?, DateMathTime> IDateHistogramCompositeAggregationSource.CalendarInterval { get; set; }
87+
Time IDateHistogramCompositeAggregationSource.FixedInterval { get; set; }
6588
string IDateHistogramCompositeAggregationSource.TimeZone { get; set; }
6689

6790
/// <inheritdoc cref="IDateHistogramCompositeAggregationSource.Interval" />
91+
[Obsolete("Use FixedInterval or CalendarInterval")]
6892
public DateHistogramCompositeAggregationSourceDescriptor<T> Interval(DateInterval? interval) =>
6993
Assign(interval, (a, v) => a.Interval = v);
7094

7195
/// <inheritdoc cref="IDateHistogramCompositeAggregationSource.Interval" />
96+
[Obsolete("Use FixedInterval or CalendarInterval")]
7297
public DateHistogramCompositeAggregationSourceDescriptor<T> Interval(Time interval) =>
7398
Assign(interval, (a, v) => a.Interval = v);
7499

100+
/// <inheritdoc cref="IDateHistogramCompositeAggregationSource.CalendarInterval" />
101+
public DateHistogramCompositeAggregationSourceDescriptor<T> CalendarInterval(DateInterval? interval) =>
102+
Assign(interval, (a, v) => a.CalendarInterval = v);
103+
104+
/// <inheritdoc cref="IDateHistogramCompositeAggregationSource.CalendarInterval" />
105+
public DateHistogramCompositeAggregationSourceDescriptor<T> CalendarInterval(DateMathTime interval) =>
106+
Assign(interval, (a, v) => a.CalendarInterval = v);
107+
108+
/// <inheritdoc cref="IDateHistogramCompositeAggregationSource.FixedInterval" />
109+
public DateHistogramCompositeAggregationSourceDescriptor<T> FixedInterval(Time interval) =>
110+
Assign(interval, (a, v) => a.FixedInterval = v);
111+
75112
/// <inheritdoc cref="IDateHistogramCompositeAggregationSource.TimeZone" />
76113
public DateHistogramCompositeAggregationSourceDescriptor<T> TimeZone(string timezone) => Assign(timezone, (a, v) => a.TimeZone = v);
77114

tests/Tests/Aggregations/Bucket/Composite/CompositeAggregationUsageTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public CompositeAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) :
6262
date_histogram = new
6363
{
6464
field = "startedOn",
65-
interval = "month"
65+
calendar_interval = "month"
6666
}
6767
}
6868
},
@@ -118,7 +118,7 @@ public CompositeAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) :
118118
)
119119
.DateHistogram("started", d => d
120120
.Field(f => f.StartedOn)
121-
.Interval(DateInterval.Month)
121+
.CalendarInterval(DateInterval.Month)
122122
)
123123
.Histogram("branch_count", h => h
124124
.Field(f => f.RequiredBranches)
@@ -151,7 +151,7 @@ public CompositeAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) :
151151
new DateHistogramCompositeAggregationSource("started")
152152
{
153153
Field = Field<Project>(f => f.StartedOn),
154-
Interval = DateInterval.Month
154+
CalendarInterval = DateInterval.Month
155155
},
156156
new HistogramCompositeAggregationSource("branch_count")
157157
{
@@ -344,7 +344,7 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
344344
}
345345

346346
//hide
347-
[SkipVersion("<6.3.0", "Date histogram source only supports format starting from Elasticsearch 6.3.0+")]
347+
[SkipVersion("<7.2.0", "Date histogram source only supports fixed_interval starting from Elasticsearch 7.2.0+")]
348348
public class DateFormatCompositeAggregationUsageTests : ProjectsOnlyAggregationUsageTestBase
349349
{
350350
public DateFormatCompositeAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { }
@@ -364,7 +364,7 @@ public DateFormatCompositeAggregationUsageTests(ReadOnlyCluster i, EndpointUsage
364364
date_histogram = new
365365
{
366366
field = "startedOn",
367-
interval = "month",
367+
fixed_interval = "30d",
368368
format = "yyyy-MM-dd"
369369
}
370370
}
@@ -396,7 +396,7 @@ public DateFormatCompositeAggregationUsageTests(ReadOnlyCluster i, EndpointUsage
396396
.Sources(s => s
397397
.DateHistogram("started", d => d
398398
.Field(f => f.StartedOn)
399-
.Interval(DateInterval.Month)
399+
.FixedInterval("30d")
400400
.Format("yyyy-MM-dd")
401401
)
402402
)
@@ -418,7 +418,7 @@ public DateFormatCompositeAggregationUsageTests(ReadOnlyCluster i, EndpointUsage
418418
new DateHistogramCompositeAggregationSource("started")
419419
{
420420
Field = Field<Project>(f => f.StartedOn),
421-
Interval = DateInterval.Month,
421+
FixedInterval = new Time(30, TimeUnit.Day),
422422
Format = "yyyy-MM-dd"
423423
},
424424
},

0 commit comments

Comments
 (0)