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 @@ -41,7 +41,7 @@ a => a
)
.DateHistogram("started", d => d
.Field(f => f.StartedOn)
.Interval(DateInterval.Month)
.CalendarInterval(DateInterval.Month)
)
.Histogram("branch_count", h => h
.Field(f => f.RequiredBranches)
Expand Down Expand Up @@ -78,7 +78,7 @@ new CompositeAggregation("my_buckets")
new DateHistogramCompositeAggregationSource("started")
{
Field = Field<Project>(f => f.StartedOn),
Interval = DateInterval.Month
CalendarInterval = DateInterval.Month
},
new HistogramCompositeAggregationSource("branch_count")
{
Expand Down Expand Up @@ -120,7 +120,7 @@ new CompositeAggregation("my_buckets")
"started": {
"date_histogram": {
"field": "startedOn",
"interval": "month"
"calendar_interval": "month"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System;
using System.Runtime.Serialization;

namespace Nest
Expand All @@ -21,11 +22,24 @@ public interface IDateHistogramCompositeAggregationSource : ICompositeAggregatio
string Format { get; set; }

/// <summary>
/// The interval to use when bucketing documents
/// The interval to use when bucketing documents
/// </summary>
[DataMember(Name ="interval")]
[Obsolete("Use FixedInterval or CalendarInterval")]
Union<DateInterval?, Time> Interval { get; set; }

/// <summary>
/// The calendar interval to use when bucketing documents
/// </summary>
[DataMember(Name ="calendar_interval")]
public Union<DateInterval?, DateMathTime> CalendarInterval { get; set; }

/// <summary>
/// The fixed interval to use when bucketing documents
/// </summary>
[DataMember(Name ="fixed_interval")]
public Time FixedInterval { get; set; }

/// <summary>
/// Used to indicate that bucketing should use a different time zone.
/// Time zones may either be specified as an ISO 8601 UTC offset (e.g. +01:00 or -08:00)
Expand All @@ -44,8 +58,15 @@ public DateHistogramCompositeAggregationSource(string name) : base(name) { }
public string Format { get; set; }

/// <inheritdoc />
[Obsolete("Use FixedInterval or CalendarInterval")]
public Union<DateInterval?, Time> Interval { get; set; }

/// <inheritdoc />
public Union<DateInterval?, DateMathTime> CalendarInterval { get; set; }

/// <inheritdoc />
public Time FixedInterval { get; set; }

/// <inheritdoc />
public string TimeZone { get; set; }

Expand All @@ -62,16 +83,32 @@ public DateHistogramCompositeAggregationSourceDescriptor(string name) : base(nam

string IDateHistogramCompositeAggregationSource.Format { get; set; }
Union<DateInterval?, Time> IDateHistogramCompositeAggregationSource.Interval { get; set; }
Union<DateInterval?, DateMathTime> IDateHistogramCompositeAggregationSource.CalendarInterval { get; set; }
Time IDateHistogramCompositeAggregationSource.FixedInterval { get; set; }
string IDateHistogramCompositeAggregationSource.TimeZone { get; set; }

/// <inheritdoc cref="IDateHistogramCompositeAggregationSource.Interval" />
[Obsolete("Use FixedInterval or CalendarInterval")]
public DateHistogramCompositeAggregationSourceDescriptor<T> Interval(DateInterval? interval) =>
Assign(interval, (a, v) => a.Interval = v);

/// <inheritdoc cref="IDateHistogramCompositeAggregationSource.Interval" />
[Obsolete("Use FixedInterval or CalendarInterval")]
public DateHistogramCompositeAggregationSourceDescriptor<T> Interval(Time interval) =>
Assign(interval, (a, v) => a.Interval = v);

/// <inheritdoc cref="IDateHistogramCompositeAggregationSource.CalendarInterval" />
public DateHistogramCompositeAggregationSourceDescriptor<T> CalendarInterval(DateInterval? interval) =>
Assign(interval, (a, v) => a.CalendarInterval = v);

/// <inheritdoc cref="IDateHistogramCompositeAggregationSource.CalendarInterval" />
public DateHistogramCompositeAggregationSourceDescriptor<T> CalendarInterval(DateMathTime interval) =>
Assign(interval, (a, v) => a.CalendarInterval = v);

/// <inheritdoc cref="IDateHistogramCompositeAggregationSource.FixedInterval" />
public DateHistogramCompositeAggregationSourceDescriptor<T> FixedInterval(Time interval) =>
Assign(interval, (a, v) => a.FixedInterval = v);

/// <inheritdoc cref="IDateHistogramCompositeAggregationSource.TimeZone" />
public DateHistogramCompositeAggregationSourceDescriptor<T> TimeZone(string timezone) => Assign(timezone, (a, v) => a.TimeZone = v);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public CompositeAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) :
date_histogram = new
{
field = "startedOn",
interval = "month"
calendar_interval = "month"
}
}
},
Expand Down Expand Up @@ -118,7 +118,7 @@ public CompositeAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) :
)
.DateHistogram("started", d => d
.Field(f => f.StartedOn)
.Interval(DateInterval.Month)
.CalendarInterval(DateInterval.Month)
)
.Histogram("branch_count", h => h
.Field(f => f.RequiredBranches)
Expand Down Expand Up @@ -151,7 +151,7 @@ public CompositeAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) :
new DateHistogramCompositeAggregationSource("started")
{
Field = Field<Project>(f => f.StartedOn),
Interval = DateInterval.Month
CalendarInterval = DateInterval.Month
},
new HistogramCompositeAggregationSource("branch_count")
{
Expand Down Expand Up @@ -344,7 +344,7 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
}

//hide
[SkipVersion("<6.3.0", "Date histogram source only supports format starting from Elasticsearch 6.3.0+")]
[SkipVersion("<7.2.0", "Date histogram source only supports fixed_interval starting from Elasticsearch 7.2.0+")]
public class DateFormatCompositeAggregationUsageTests : ProjectsOnlyAggregationUsageTestBase
{
public DateFormatCompositeAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { }
Expand All @@ -364,7 +364,7 @@ public DateFormatCompositeAggregationUsageTests(ReadOnlyCluster i, EndpointUsage
date_histogram = new
{
field = "startedOn",
interval = "month",
fixed_interval = "30d",
format = "yyyy-MM-dd"
}
}
Expand Down Expand Up @@ -396,7 +396,7 @@ public DateFormatCompositeAggregationUsageTests(ReadOnlyCluster i, EndpointUsage
.Sources(s => s
.DateHistogram("started", d => d
.Field(f => f.StartedOn)
.Interval(DateInterval.Month)
.FixedInterval("30d")
.Format("yyyy-MM-dd")
)
)
Expand All @@ -418,7 +418,7 @@ public DateFormatCompositeAggregationUsageTests(ReadOnlyCluster i, EndpointUsage
new DateHistogramCompositeAggregationSource("started")
{
Field = Field<Project>(f => f.StartedOn),
Interval = DateInterval.Month,
FixedInterval = new Time(30, TimeUnit.Day),
Format = "yyyy-MM-dd"
},
},
Expand Down