Skip to content

Commit 354c551

Browse files
committed
Add minimum_interval to AutoDateHistogram aggregation
Relates: #4001 This commit adds the minimum_interval property to auto date histogram aggregation. A new enum needs to be introduced for this as DateInterval contains values that are invalid for the minimum_interval.
1 parent ee84e1a commit 354c551

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/Nest/Aggregations/Bucket/AutoDateHistogram/AutoDateHistogramAggregation.cs

+14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ public interface IAutoDateHistogramAggregation : IBucketAggregation
3333

3434
[DataMember(Name = "time_zone")]
3535
string TimeZone { get; set; }
36+
37+
/// <summary>
38+
/// Specify the minimum rounding interval that should be used. This can make the collection process
39+
/// more efficient, as the aggregation will not attempt to round at any interval lower than this.
40+
/// </summary>
41+
[DataMember(Name = "minimum_interval")]
42+
MinimumInterval? MinimumInterval { get; set; }
3643
}
3744

3845
public class AutoDateHistogramAggregation : BucketAggregationBase, IAutoDateHistogramAggregation
@@ -64,6 +71,8 @@ public string Format
6471
public IScript Script { get; set; }
6572
public string TimeZone { get; set; }
6673

74+
public MinimumInterval? MinimumInterval { get; set; }
75+
6776
internal override void WrapInContainer(AggregationContainer c) => c.AutoDateHistogram = this;
6877
}
6978

@@ -99,6 +108,8 @@ string IAutoDateHistogramAggregation.Format
99108

100109
string IAutoDateHistogramAggregation.TimeZone { get; set; }
101110

111+
MinimumInterval? IAutoDateHistogramAggregation.MinimumInterval { get; set; }
112+
102113
public AutoDateHistogramAggregationDescriptor<T> Field(Field field) => Assign(field, (a, v) => a.Field = v);
103114

104115
public AutoDateHistogramAggregationDescriptor<T> Field<TValue>(Expression<Func<T, TValue>> field) => Assign(field, (a, v) => a.Field = v);
@@ -117,5 +128,8 @@ public AutoDateHistogramAggregationDescriptor<T> Script(Func<ScriptDescriptor, I
117128
public AutoDateHistogramAggregationDescriptor<T> Offset(string offset) => Assign(offset, (a, v) => a.Offset = v);
118129

119130
public AutoDateHistogramAggregationDescriptor<T> Missing(DateTime? missing) => Assign(missing, (a, v) => a.Missing = v);
131+
132+
/// <inheritdoc cref="IAutoDateHistogramAggregation.MinimumInterval"/>
133+
public AutoDateHistogramAggregationDescriptor<T> MinimumInterval(MinimumInterval? minimumInterval) => Assign(minimumInterval, (a, v) => a.MinimumInterval = v);
120134
}
121135
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Runtime.Serialization;
2+
using Elasticsearch.Net;
3+
4+
namespace Nest
5+
{
6+
[StringEnum]
7+
public enum MinimumInterval
8+
{
9+
[EnumMember(Value = "second")]
10+
Second,
11+
12+
[EnumMember(Value = "minute")]
13+
Minute,
14+
15+
[EnumMember(Value = "hour")]
16+
Hour,
17+
18+
[EnumMember(Value = "day")]
19+
Day,
20+
21+
[EnumMember(Value = "month")]
22+
Month,
23+
24+
[EnumMember(Value = "year")]
25+
Year
26+
}
27+
}

src/Tests/Tests/Aggregations/Bucket/AutoDateHistogram/AutoDateHistogramAggregationUsageTests.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public AutoDateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u
3636
field = "startedOn",
3737
buckets = 10,
3838
format = "yyyy-MM-dd'T'HH:mm:ss||date_optional_time", //<1> Note the inclusion of `date_optional_time` to `format`
39-
missing = FixedDate
39+
missing = FixedDate,
40+
minimum_interval = "day"
4041
},
4142
aggs = new
4243
{
@@ -64,6 +65,7 @@ public AutoDateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u
6465
.Buckets(10)
6566
.Format("yyyy-MM-dd'T'HH:mm:ss")
6667
.Missing(FixedDate)
68+
.MinimumInterval(MinimumInterval.Day)
6769
.Aggregations(childAggs => childAggs
6870
.Nested("project_tags", n => n
6971
.Path(p => p.Tags)
@@ -81,6 +83,7 @@ public AutoDateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u
8183
Buckets = 10,
8284
Format = "yyyy-MM-dd'T'HH:mm:ss",
8385
Missing = FixedDate,
86+
MinimumInterval = MinimumInterval.Day,
8487
Aggregations = new NestedAggregation("project_tags")
8588
{
8689
Path = Field<Project>(p => p.Tags),

0 commit comments

Comments
 (0)