Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "Second" facet date interval and support for custom date intervals... #715

Closed
wants to merge 1 commit into from
Closed
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
30 changes: 28 additions & 2 deletions src/Nest/DSL/Facets/DateHistogramFacetDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,34 @@ public DateHistogramFacetDescriptor<T> OnField(Expression<Func<T, object>> objec
objectPath.ThrowIfNull("objectPath");
Self.Field = objectPath;
return this;
}
public DateHistogramFacetDescriptor<T> Interval(DateInterval interval)
}
/// <summary>
/// Added to support custom date intervals on date histogram facet. Eg: "5s" for 5 seconds interval.
/// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-date-histogram-facet.html#_interval
/// </summary>
/// <param name="interval">Custom interval string</param>
/// <returns></returns>
public DateHistogramFacetDescriptor<T> Interval(string interval)
{
var intervalString = interval.ToLowerInvariant();
Self.Interval = intervalString;
return this;
}
/// <summary>
/// Added to support custom date intervals on date histogram facet. Eg: "5s" for 5 seconds interval.
/// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-date-histogram-facet.html#_interval
/// </summary>
/// <param name="interval">Custom interval string</param>
/// <param name="dateRounding">Date rounding type</param>
/// <returns></returns>
public DateHistogramFacetDescriptor<T> Interval(string interval, DateRounding dateRounding)
{
var intervalString = interval.ToLowerInvariant();
var roundingString = Enum.GetName(typeof(DateRounding), dateRounding).ToLowerInvariant();
Self.Interval = intervalString + ":" + roundingString;
return this;
}
public DateHistogramFacetDescriptor<T> Interval(DateInterval interval)
{
var intervalString = Enum.GetName(typeof(DateInterval), interval).ToLowerInvariant();
Self.Interval = intervalString;
Expand Down
2 changes: 1 addition & 1 deletion src/Nest/DSL/Facets/DateInterval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace Nest
{
public enum DateInterval
{
Minute, Hour, Day, Week, Month, Quarter, Year
Second, Minute, Hour, Day, Week, Month, Quarter, Year
}
}