Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public interface IAutoDateHistogramAggregation : IBucketAggregation
[JsonProperty("field")]
Field Field { get; set; }

[JsonProperty("buckets")]
int? Buckets { get; set; }

[JsonProperty("format")]
string Format { get; set; }

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

public Field Field { get; set; }

public int? Buckets { get; set; }

//see: https://github.com/elastic/elasticsearch/issues/9725
public string Format
{
Expand Down Expand Up @@ -70,6 +75,8 @@ public class AutoDateHistogramAggregationDescriptor<T>

Field IAutoDateHistogramAggregation.Field { get; set; }

int? IAutoDateHistogramAggregation.Buckets { get; set; }

//see: https://github.com/elastic/elasticsearch/issues/9725
string IAutoDateHistogramAggregation.Format
{
Expand All @@ -95,6 +102,8 @@ string IAutoDateHistogramAggregation.Format

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

public AutoDateHistogramAggregationDescriptor<T> Buckets(int? buckets) => Assign(buckets, (a, v) => a.Buckets = v);

public AutoDateHistogramAggregationDescriptor<T> Script(string script) => Assign((InlineScript)script, (a, v) => a.Script = v);

public AutoDateHistogramAggregationDescriptor<T> Script(Func<ScriptDescriptor, IScript> scriptSelector) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public AutoDateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u
auto_date_histogram = new
{
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
},
Expand All @@ -62,6 +63,7 @@ public AutoDateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.AutoDateHistogram("projects_started_per_month", date => date
.Field(p => p.StartedOn)
.Buckets(10)
.Format("yyyy-MM-dd'T'HH:mm:ss")
.Missing(FixedDate)
.Aggregations(childAggs => childAggs
Expand All @@ -78,6 +80,7 @@ public AutoDateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u
new AutoDateHistogramAggregation("projects_started_per_month")
{
Field = Field<Project>(p => p.StartedOn),
Buckets = 10,
Format = "yyyy-MM-dd'T'HH:mm:ss",
Missing = FixedDate,
Aggregations = new NestedAggregation("project_tags")
Expand Down