Skip to content

Commit 6f30bf7

Browse files
committed
Add buckets to AutoDateHistogramAggregation. #3758
1 parent e8d565c commit 6f30bf7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public interface IAutoDateHistogramAggregation : IBucketAggregation
1313
[DataMember(Name = "field")]
1414
Field Field { get; set; }
1515

16+
[DataMember(Name = "buckets")]
17+
int? Buckets { get; set; }
18+
1619
[DataMember(Name = "format")]
1720
string Format { get; set; }
1821

@@ -42,6 +45,8 @@ public AutoDateHistogramAggregation(string name) : base(name) { }
4245

4346
public Field Field { get; set; }
4447

48+
public int? Buckets { get; set; }
49+
4550
//see: https://github.com/elastic/elasticsearch/issues/9725
4651
public string Format
4752
{
@@ -71,6 +76,8 @@ public class AutoDateHistogramAggregationDescriptor<T>
7176

7277
Field IAutoDateHistogramAggregation.Field { get; set; }
7378

79+
int? IAutoDateHistogramAggregation.Buckets { get; set; }
80+
7481
//see: https://github.com/elastic/elasticsearch/issues/9725
7582
string IAutoDateHistogramAggregation.Format
7683
{
@@ -96,6 +103,8 @@ string IAutoDateHistogramAggregation.Format
96103

97104
public AutoDateHistogramAggregationDescriptor<T> Field<TValue>(Expression<Func<T, TValue>> field) => Assign(field, (a, v) => a.Field = v);
98105

106+
public AutoDateHistogramAggregationDescriptor<T> Buckets(int? buckets) => Assign(buckets, (a, v) => a.Buckets = v);
107+
99108
public AutoDateHistogramAggregationDescriptor<T> Script(string script) => Assign((InlineScript)script, (a, v) => a.Script = v);
100109

101110
public AutoDateHistogramAggregationDescriptor<T> Script(Func<ScriptDescriptor, IScript> scriptSelector) =>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public AutoDateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u
3636
auto_date_histogram = new
3737
{
3838
field = "startedOn",
39+
buckets = 10,
3940
format = "yyyy-MM-dd'T'HH:mm:ss||date_optional_time", //<1> Note the inclusion of `date_optional_time` to `format`
4041
missing = FixedDate
4142
},
@@ -62,6 +63,7 @@ public AutoDateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u
6263
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
6364
.AutoDateHistogram("projects_started_per_month", date => date
6465
.Field(p => p.StartedOn)
66+
.Buckets(10)
6567
.Format("yyyy-MM-dd'T'HH:mm:ss")
6668
.Missing(FixedDate)
6769
.Aggregations(childAggs => childAggs
@@ -78,6 +80,7 @@ public AutoDateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u
7880
new AutoDateHistogramAggregation("projects_started_per_month")
7981
{
8082
Field = Field<Project>(p => p.StartedOn),
83+
Buckets = 10,
8184
Format = "yyyy-MM-dd'T'HH:mm:ss",
8285
Missing = FixedDate,
8386
Aggregations = new NestedAggregation("project_tags")

0 commit comments

Comments
 (0)