Skip to content

Commit

Permalink
Add minimum_interval to AutoDateHistogram aggregation (#4053)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
russcam committed Aug 30, 2019
1 parent 86bcc2c commit f523ace
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public interface IAutoDateHistogramAggregation : IBucketAggregation

[DataMember(Name = "time_zone")]
string TimeZone { get; set; }

/// <summary>
/// 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.
/// </summary>
[DataMember(Name = "minimum_interval")]
MinimumInterval? MinimumInterval { get; set; }
}

public class AutoDateHistogramAggregation : BucketAggregationBase, IAutoDateHistogramAggregation
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -99,6 +108,8 @@ string IAutoDateHistogramAggregation.Format

string IAutoDateHistogramAggregation.TimeZone { get; set; }

MinimumInterval? IAutoDateHistogramAggregation.MinimumInterval { get; set; }

public AutoDateHistogramAggregationDescriptor<T> Field(Field field) => Assign(field, (a, v) => a.Field = v);

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

public AutoDateHistogramAggregationDescriptor<T> Missing(DateTime? missing) => Assign(missing, (a, v) => a.Missing = v);

/// <inheritdoc cref="IAutoDateHistogramAggregation.MinimumInterval"/>
public AutoDateHistogramAggregationDescriptor<T> MinimumInterval(MinimumInterval? minimumInterval) => Assign(minimumInterval, (a, v) => a.MinimumInterval = v);
}
}
27 changes: 27 additions & 0 deletions src/Nest/Aggregations/Bucket/AutoDateHistogram/MinimumInterval.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand All @@ -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<Project>(p => p.Tags),
Expand Down

0 comments on commit f523ace

Please sign in to comment.