Skip to content

Commit

Permalink
Implement extended_bounds and hard_bounds for `{Date}HistogramAgg…
Browse files Browse the repository at this point in the history
…regation` (#8140)
  • Loading branch information
flobernd committed Apr 18, 2024
1 parent cf25664 commit d574208
Show file tree
Hide file tree
Showing 8 changed files with 1,148 additions and 0 deletions.
Expand Up @@ -35,6 +35,12 @@ public sealed partial class DateHistogramAggregation
[JsonInclude, JsonPropertyName("calendar_interval")]
public Elastic.Clients.Elasticsearch.Serverless.Aggregations.CalendarInterval? CalendarInterval { get; set; }

/// <summary>
/// <para>Enables extending the bounds of the histogram beyond the data itself.</para>
/// </summary>
[JsonInclude, JsonPropertyName("extended_bounds")]
public Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDate? ExtendedBounds { get; set; }

/// <summary>
/// <para>The date field whose values are use to build a histogram.</para>
/// </summary>
Expand All @@ -53,6 +59,12 @@ public sealed partial class DateHistogramAggregation
[JsonInclude, JsonPropertyName("format")]
public string? Format { get; set; }

/// <summary>
/// <para>Limits the histogram to specified bounds.</para>
/// </summary>
[JsonInclude, JsonPropertyName("hard_bounds")]
public Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDate? HardBounds { get; set; }

/// <summary>
/// <para>Only returns buckets that have `min_doc_count` number of documents.<br/>By default, all buckets between the first bucket that matches documents and the last one are returned.</para>
/// </summary>
Expand Down Expand Up @@ -101,9 +113,15 @@ public DateHistogramAggregationDescriptor() : base()
}

private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CalendarInterval? CalendarIntervalValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDate? ExtendedBoundsValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor ExtendedBoundsDescriptor { get; set; }
private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor> ExtendedBoundsDescriptorAction { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Field? FieldValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Duration? FixedIntervalValue { get; set; }
private string? FormatValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDate? HardBoundsValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor HardBoundsDescriptor { get; set; }
private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor> HardBoundsDescriptorAction { get; set; }
private int? MinDocCountValue { get; set; }
private DateTimeOffset? MissingValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Duration? OffsetValue { get; set; }
Expand All @@ -121,6 +139,33 @@ public DateHistogramAggregationDescriptor<TDocument> CalendarInterval(Elastic.Cl
return Self;
}

/// <summary>
/// <para>Enables extending the bounds of the histogram beyond the data itself.</para>
/// </summary>
public DateHistogramAggregationDescriptor<TDocument> ExtendedBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDate? extendedBounds)
{
ExtendedBoundsDescriptor = null;
ExtendedBoundsDescriptorAction = null;
ExtendedBoundsValue = extendedBounds;
return Self;
}

public DateHistogramAggregationDescriptor<TDocument> ExtendedBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor descriptor)
{
ExtendedBoundsValue = null;
ExtendedBoundsDescriptorAction = null;
ExtendedBoundsDescriptor = descriptor;
return Self;
}

public DateHistogramAggregationDescriptor<TDocument> ExtendedBounds(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor> configure)
{
ExtendedBoundsValue = null;
ExtendedBoundsDescriptor = null;
ExtendedBoundsDescriptorAction = configure;
return Self;
}

/// <summary>
/// <para>The date field whose values are use to build a histogram.</para>
/// </summary>
Expand Down Expand Up @@ -166,6 +211,33 @@ public DateHistogramAggregationDescriptor<TDocument> Format(string? format)
return Self;
}

/// <summary>
/// <para>Limits the histogram to specified bounds.</para>
/// </summary>
public DateHistogramAggregationDescriptor<TDocument> HardBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDate? hardBounds)
{
HardBoundsDescriptor = null;
HardBoundsDescriptorAction = null;
HardBoundsValue = hardBounds;
return Self;
}

public DateHistogramAggregationDescriptor<TDocument> HardBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor descriptor)
{
HardBoundsValue = null;
HardBoundsDescriptorAction = null;
HardBoundsDescriptor = descriptor;
return Self;
}

public DateHistogramAggregationDescriptor<TDocument> HardBounds(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor> configure)
{
HardBoundsValue = null;
HardBoundsDescriptor = null;
HardBoundsDescriptorAction = configure;
return Self;
}

/// <summary>
/// <para>Only returns buckets that have `min_doc_count` number of documents.<br/>By default, all buckets between the first bucket that matches documents and the last one are returned.</para>
/// </summary>
Expand Down Expand Up @@ -232,6 +304,22 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
JsonSerializer.Serialize(writer, CalendarIntervalValue, options);
}

if (ExtendedBoundsDescriptor is not null)
{
writer.WritePropertyName("extended_bounds");
JsonSerializer.Serialize(writer, ExtendedBoundsDescriptor, options);
}
else if (ExtendedBoundsDescriptorAction is not null)
{
writer.WritePropertyName("extended_bounds");
JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor(ExtendedBoundsDescriptorAction), options);
}
else if (ExtendedBoundsValue is not null)
{
writer.WritePropertyName("extended_bounds");
JsonSerializer.Serialize(writer, ExtendedBoundsValue, options);
}

if (FieldValue is not null)
{
writer.WritePropertyName("field");
Expand All @@ -250,6 +338,22 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
writer.WriteStringValue(FormatValue);
}

if (HardBoundsDescriptor is not null)
{
writer.WritePropertyName("hard_bounds");
JsonSerializer.Serialize(writer, HardBoundsDescriptor, options);
}
else if (HardBoundsDescriptorAction is not null)
{
writer.WritePropertyName("hard_bounds");
JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor(HardBoundsDescriptorAction), options);
}
else if (HardBoundsValue is not null)
{
writer.WritePropertyName("hard_bounds");
JsonSerializer.Serialize(writer, HardBoundsValue, options);
}

if (MinDocCountValue.HasValue)
{
writer.WritePropertyName("min_doc_count");
Expand Down Expand Up @@ -305,9 +409,15 @@ public DateHistogramAggregationDescriptor() : base()
}

private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CalendarInterval? CalendarIntervalValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDate? ExtendedBoundsValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor ExtendedBoundsDescriptor { get; set; }
private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor> ExtendedBoundsDescriptorAction { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Field? FieldValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Duration? FixedIntervalValue { get; set; }
private string? FormatValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDate? HardBoundsValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor HardBoundsDescriptor { get; set; }
private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor> HardBoundsDescriptorAction { get; set; }
private int? MinDocCountValue { get; set; }
private DateTimeOffset? MissingValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Duration? OffsetValue { get; set; }
Expand All @@ -325,6 +435,33 @@ public DateHistogramAggregationDescriptor CalendarInterval(Elastic.Clients.Elast
return Self;
}

/// <summary>
/// <para>Enables extending the bounds of the histogram beyond the data itself.</para>
/// </summary>
public DateHistogramAggregationDescriptor ExtendedBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDate? extendedBounds)
{
ExtendedBoundsDescriptor = null;
ExtendedBoundsDescriptorAction = null;
ExtendedBoundsValue = extendedBounds;
return Self;
}

public DateHistogramAggregationDescriptor ExtendedBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor descriptor)
{
ExtendedBoundsValue = null;
ExtendedBoundsDescriptorAction = null;
ExtendedBoundsDescriptor = descriptor;
return Self;
}

public DateHistogramAggregationDescriptor ExtendedBounds(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor> configure)
{
ExtendedBoundsValue = null;
ExtendedBoundsDescriptor = null;
ExtendedBoundsDescriptorAction = configure;
return Self;
}

/// <summary>
/// <para>The date field whose values are use to build a histogram.</para>
/// </summary>
Expand Down Expand Up @@ -370,6 +507,33 @@ public DateHistogramAggregationDescriptor Format(string? format)
return Self;
}

/// <summary>
/// <para>Limits the histogram to specified bounds.</para>
/// </summary>
public DateHistogramAggregationDescriptor HardBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDate? hardBounds)
{
HardBoundsDescriptor = null;
HardBoundsDescriptorAction = null;
HardBoundsValue = hardBounds;
return Self;
}

public DateHistogramAggregationDescriptor HardBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor descriptor)
{
HardBoundsValue = null;
HardBoundsDescriptorAction = null;
HardBoundsDescriptor = descriptor;
return Self;
}

public DateHistogramAggregationDescriptor HardBounds(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor> configure)
{
HardBoundsValue = null;
HardBoundsDescriptor = null;
HardBoundsDescriptorAction = configure;
return Self;
}

/// <summary>
/// <para>Only returns buckets that have `min_doc_count` number of documents.<br/>By default, all buckets between the first bucket that matches documents and the last one are returned.</para>
/// </summary>
Expand Down Expand Up @@ -436,6 +600,22 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
JsonSerializer.Serialize(writer, CalendarIntervalValue, options);
}

if (ExtendedBoundsDescriptor is not null)
{
writer.WritePropertyName("extended_bounds");
JsonSerializer.Serialize(writer, ExtendedBoundsDescriptor, options);
}
else if (ExtendedBoundsDescriptorAction is not null)
{
writer.WritePropertyName("extended_bounds");
JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor(ExtendedBoundsDescriptorAction), options);
}
else if (ExtendedBoundsValue is not null)
{
writer.WritePropertyName("extended_bounds");
JsonSerializer.Serialize(writer, ExtendedBoundsValue, options);
}

if (FieldValue is not null)
{
writer.WritePropertyName("field");
Expand All @@ -454,6 +634,22 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
writer.WriteStringValue(FormatValue);
}

if (HardBoundsDescriptor is not null)
{
writer.WritePropertyName("hard_bounds");
JsonSerializer.Serialize(writer, HardBoundsDescriptor, options);
}
else if (HardBoundsDescriptorAction is not null)
{
writer.WritePropertyName("hard_bounds");
JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsDateDescriptor(HardBoundsDescriptorAction), options);
}
else if (HardBoundsValue is not null)
{
writer.WritePropertyName("hard_bounds");
JsonSerializer.Serialize(writer, HardBoundsValue, options);
}

if (MinDocCountValue.HasValue)
{
writer.WritePropertyName("min_doc_count");
Expand Down
@@ -0,0 +1,91 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// 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.
//
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Aggregations;

public sealed partial class ExtendedBoundsDate
{
/// <summary>
/// <para>Maximum value for the bound.</para>
/// </summary>
[JsonInclude, JsonPropertyName("max")]
public Elastic.Clients.Elasticsearch.Serverless.Aggregations.FieldDateMath? Max { get; set; }

/// <summary>
/// <para>Minimum value for the bound.</para>
/// </summary>
[JsonInclude, JsonPropertyName("min")]
public Elastic.Clients.Elasticsearch.Serverless.Aggregations.FieldDateMath? Min { get; set; }
}

public sealed partial class ExtendedBoundsDateDescriptor : SerializableDescriptor<ExtendedBoundsDateDescriptor>
{
internal ExtendedBoundsDateDescriptor(Action<ExtendedBoundsDateDescriptor> configure) => configure.Invoke(this);

public ExtendedBoundsDateDescriptor() : base()
{
}

private Elastic.Clients.Elasticsearch.Serverless.Aggregations.FieldDateMath? MaxValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Aggregations.FieldDateMath? MinValue { get; set; }

/// <summary>
/// <para>Maximum value for the bound.</para>
/// </summary>
public ExtendedBoundsDateDescriptor Max(Elastic.Clients.Elasticsearch.Serverless.Aggregations.FieldDateMath? max)
{
MaxValue = max;
return Self;
}

/// <summary>
/// <para>Minimum value for the bound.</para>
/// </summary>
public ExtendedBoundsDateDescriptor Min(Elastic.Clients.Elasticsearch.Serverless.Aggregations.FieldDateMath? min)
{
MinValue = min;
return Self;
}

protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
{
writer.WriteStartObject();
if (MaxValue is not null)
{
writer.WritePropertyName("max");
JsonSerializer.Serialize(writer, MaxValue, options);
}

if (MinValue is not null)
{
writer.WritePropertyName("min");
JsonSerializer.Serialize(writer, MinValue, options);
}

writer.WriteEndObject();
}
}

0 comments on commit d574208

Please sign in to comment.