Skip to content

Commit 4ed8ab1

Browse files
authored
Add buckets to AutoDateHistogramAggregation. (#3758)
Fixes #3754
1 parent a337b32 commit 4ed8ab1

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
@@ -12,6 +12,9 @@ public interface IAutoDateHistogramAggregation : IBucketAggregation
1212
[JsonProperty("field")]
1313
Field Field { get; set; }
1414

15+
[JsonProperty("buckets")]
16+
int? Buckets { get; set; }
17+
1518
[JsonProperty("format")]
1619
string Format { get; set; }
1720

@@ -41,6 +44,8 @@ public AutoDateHistogramAggregation(string name) : base(name) { }
4144

4245
public Field Field { get; set; }
4346

47+
public int? Buckets { get; set; }
48+
4449
//see: https://github.com/elastic/elasticsearch/issues/9725
4550
public string Format
4651
{
@@ -70,6 +75,8 @@ public class AutoDateHistogramAggregationDescriptor<T>
7075

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

78+
int? IAutoDateHistogramAggregation.Buckets { get; set; }
79+
7380
//see: https://github.com/elastic/elasticsearch/issues/9725
7481
string IAutoDateHistogramAggregation.Format
7582
{
@@ -95,6 +102,8 @@ string IAutoDateHistogramAggregation.Format
95102

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

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

100109
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)