From 354c551dbcafc280b76892a377d05b27564dec8a Mon Sep 17 00:00:00 2001 From: Russ Cam Date: Wed, 28 Aug 2019 13:16:20 +1000 Subject: [PATCH] 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. --- .../AutoDateHistogramAggregation.cs | 14 ++++++++++ .../AutoDateHistogram/MinimumInterval.cs | 27 +++++++++++++++++++ .../AutoDateHistogramAggregationUsageTests.cs | 5 +++- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/Nest/Aggregations/Bucket/AutoDateHistogram/MinimumInterval.cs diff --git a/src/Nest/Aggregations/Bucket/AutoDateHistogram/AutoDateHistogramAggregation.cs b/src/Nest/Aggregations/Bucket/AutoDateHistogram/AutoDateHistogramAggregation.cs index 25776172351..230867be8f1 100644 --- a/src/Nest/Aggregations/Bucket/AutoDateHistogram/AutoDateHistogramAggregation.cs +++ b/src/Nest/Aggregations/Bucket/AutoDateHistogram/AutoDateHistogramAggregation.cs @@ -33,6 +33,13 @@ public interface IAutoDateHistogramAggregation : IBucketAggregation [DataMember(Name = "time_zone")] string TimeZone { get; set; } + + /// + /// Specify the minimum rounding interval that should be used. This can make the collection process + /// more efficient, as the aggregation will not attempt to round at any interval lower than this. + /// + [DataMember(Name = "minimum_interval")] + MinimumInterval? MinimumInterval { get; set; } } public class AutoDateHistogramAggregation : BucketAggregationBase, IAutoDateHistogramAggregation @@ -64,6 +71,8 @@ public string Format public IScript Script { get; set; } public string TimeZone { get; set; } + public MinimumInterval? MinimumInterval { get; set; } + internal override void WrapInContainer(AggregationContainer c) => c.AutoDateHistogram = this; } @@ -99,6 +108,8 @@ string IAutoDateHistogramAggregation.Format string IAutoDateHistogramAggregation.TimeZone { get; set; } + MinimumInterval? IAutoDateHistogramAggregation.MinimumInterval { get; set; } + public AutoDateHistogramAggregationDescriptor Field(Field field) => Assign(field, (a, v) => a.Field = v); public AutoDateHistogramAggregationDescriptor Field(Expression> field) => Assign(field, (a, v) => a.Field = v); @@ -117,5 +128,8 @@ public AutoDateHistogramAggregationDescriptor Script(Func Offset(string offset) => Assign(offset, (a, v) => a.Offset = v); public AutoDateHistogramAggregationDescriptor Missing(DateTime? missing) => Assign(missing, (a, v) => a.Missing = v); + + /// + public AutoDateHistogramAggregationDescriptor MinimumInterval(MinimumInterval? minimumInterval) => Assign(minimumInterval, (a, v) => a.MinimumInterval = v); } } diff --git a/src/Nest/Aggregations/Bucket/AutoDateHistogram/MinimumInterval.cs b/src/Nest/Aggregations/Bucket/AutoDateHistogram/MinimumInterval.cs new file mode 100644 index 00000000000..735fb124115 --- /dev/null +++ b/src/Nest/Aggregations/Bucket/AutoDateHistogram/MinimumInterval.cs @@ -0,0 +1,27 @@ +using System.Runtime.Serialization; +using Elasticsearch.Net; + +namespace Nest +{ + [StringEnum] + public enum MinimumInterval + { + [EnumMember(Value = "second")] + Second, + + [EnumMember(Value = "minute")] + Minute, + + [EnumMember(Value = "hour")] + Hour, + + [EnumMember(Value = "day")] + Day, + + [EnumMember(Value = "month")] + Month, + + [EnumMember(Value = "year")] + Year + } +} diff --git a/src/Tests/Tests/Aggregations/Bucket/AutoDateHistogram/AutoDateHistogramAggregationUsageTests.cs b/src/Tests/Tests/Aggregations/Bucket/AutoDateHistogram/AutoDateHistogramAggregationUsageTests.cs index 11d8657547a..075d1c8b6da 100644 --- a/src/Tests/Tests/Aggregations/Bucket/AutoDateHistogram/AutoDateHistogramAggregationUsageTests.cs +++ b/src/Tests/Tests/Aggregations/Bucket/AutoDateHistogram/AutoDateHistogramAggregationUsageTests.cs @@ -36,7 +36,8 @@ public AutoDateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u field = "startedOn", buckets = 10, format = "yyyy-MM-dd'T'HH:mm:ss||date_optional_time", //<1> Note the inclusion of `date_optional_time` to `format` - missing = FixedDate + missing = FixedDate, + minimum_interval = "day" }, aggs = new { @@ -64,6 +65,7 @@ public AutoDateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u .Buckets(10) .Format("yyyy-MM-dd'T'HH:mm:ss") .Missing(FixedDate) + .MinimumInterval(MinimumInterval.Day) .Aggregations(childAggs => childAggs .Nested("project_tags", n => n .Path(p => p.Tags) @@ -81,6 +83,7 @@ public AutoDateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u Buckets = 10, Format = "yyyy-MM-dd'T'HH:mm:ss", Missing = FixedDate, + MinimumInterval = MinimumInterval.Day, Aggregations = new NestedAggregation("project_tags") { Path = Field(p => p.Tags),