Skip to content

[Backport 8.1] Support cumulative sum aggregation. #7438

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

Merged
merged 1 commit into from
Mar 22, 2023
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 @@ -407,8 +407,14 @@ public static void ReadAggregate(ref Utf8JsonReader reader, JsonSerializerOption
break;
}

case "cumulative_sum":
throw new Exception("The aggregate in response is not yet supported.");
// Used by:
// - cumulative sum aggregation
case "simple_value":
{
var agg = JsonSerializer.Deserialize<SimpleValueAggregate>(ref reader, options);
dictionary.Add(nameParts[1], agg);
break;
}

case "derivative":
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public sealed class FieldCapsRequestParameters : RequestParameters
/// </summary>
public ICollection<Elastic.Clients.Elasticsearch.ExpandWildcard>? ExpandWildcards { get => Q<ICollection<Elastic.Clients.Elasticsearch.ExpandWildcard>?>("expand_wildcards"); set => Q("expand_wildcards", value); }

/// <summary>
/// <para>Comma-separated list of fields to retrieve capabilities for. Wildcard (`*`) expressions are supported.</para>
/// </summary>
public Elastic.Clients.Elasticsearch.Fields? Fields { get => Q<Elastic.Clients.Elasticsearch.Fields?>("fields"); set => Q("fields", value); }

/// <summary>
/// <para>If `true`, missing or closed indices are not included in the response.</para>
/// </summary>
Expand Down Expand Up @@ -98,12 +93,6 @@ public FieldCapsRequest(Elastic.Clients.Elasticsearch.Indices? indices) : base(r
[JsonIgnore]
public ICollection<Elastic.Clients.Elasticsearch.ExpandWildcard>? ExpandWildcards { get => Q<ICollection<Elastic.Clients.Elasticsearch.ExpandWildcard>?>("expand_wildcards"); set => Q("expand_wildcards", value); }

/// <summary>
/// <para>Comma-separated list of fields to retrieve capabilities for. Wildcard (`*`) expressions are supported.</para>
/// </summary>
[JsonIgnore]
public Elastic.Clients.Elasticsearch.Fields? Fields { get => Q<Elastic.Clients.Elasticsearch.Fields?>("fields"); set => Q("fields", value); }

/// <summary>
/// <para>If `true`, missing or closed indices are not included in the response.</para>
/// </summary>
Expand All @@ -128,6 +117,12 @@ public FieldCapsRequest(Elastic.Clients.Elasticsearch.Indices? indices) : base(r
[JsonIgnore]
public ICollection<string>? Types { get => Q<ICollection<string>?>("types"); set => Q("types", value); }

/// <summary>
/// <para>List of fields to retrieve capabilities for. Wildcard (`*`) expressions are supported.</para>
/// </summary>
[JsonInclude, JsonPropertyName("fields")]
public Elastic.Clients.Elasticsearch.Fields? Fields { get; set; }

/// <summary>
/// <para>Allows to filter indices if the provided query rewrites to match_none on every shard.</para>
/// </summary>
Expand Down Expand Up @@ -160,7 +155,6 @@ public FieldCapsRequestDescriptor()

public FieldCapsRequestDescriptor<TDocument> AllowNoIndices(bool? allowNoIndices = true) => Qs("allow_no_indices", allowNoIndices);
public FieldCapsRequestDescriptor<TDocument> ExpandWildcards(ICollection<Elastic.Clients.Elasticsearch.ExpandWildcard>? expandWildcards) => Qs("expand_wildcards", expandWildcards);
public FieldCapsRequestDescriptor<TDocument> Fields(Elastic.Clients.Elasticsearch.Fields? fields) => Qs("fields", fields);
public FieldCapsRequestDescriptor<TDocument> Filters(string? filters) => Qs("filters", filters);
public FieldCapsRequestDescriptor<TDocument> IgnoreUnavailable(bool? ignoreUnavailable = true) => Qs("ignore_unavailable", ignoreUnavailable);
public FieldCapsRequestDescriptor<TDocument> IncludeUnmapped(bool? includeUnmapped = true) => Qs("include_unmapped", includeUnmapped);
Expand All @@ -175,6 +169,7 @@ public FieldCapsRequestDescriptor<TDocument> Indices(Elastic.Clients.Elasticsear
private Elastic.Clients.Elasticsearch.QueryDsl.Query? IndexFilterValue { get; set; }
private QueryDsl.QueryDescriptor<TDocument> IndexFilterDescriptor { get; set; }
private Action<QueryDsl.QueryDescriptor<TDocument>> IndexFilterDescriptorAction { get; set; }
private Elastic.Clients.Elasticsearch.Fields? FieldsValue { get; set; }
private IDictionary<Elastic.Clients.Elasticsearch.Field, Elastic.Clients.Elasticsearch.Mapping.RuntimeField>? RuntimeMappingsValue { get; set; }

/// <summary>
Expand Down Expand Up @@ -204,6 +199,15 @@ public FieldCapsRequestDescriptor<TDocument> IndexFilter(Action<QueryDsl.QueryDe
return Self;
}

/// <summary>
/// <para>List of fields to retrieve capabilities for. Wildcard (`*`) expressions are supported.</para>
/// </summary>
public FieldCapsRequestDescriptor<TDocument> Fields(Elastic.Clients.Elasticsearch.Fields? fields)
{
FieldsValue = fields;
return Self;
}

/// <summary>
/// <para>Defines ad-hoc runtime fields in the request similar to the way it is done in search requests.<br/>These fields exist only as part of the query and take precedence over fields defined with the same name in the index mappings.</para>
/// </summary>
Expand Down Expand Up @@ -232,6 +236,12 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
JsonSerializer.Serialize(writer, IndexFilterValue, options);
}

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

if (RuntimeMappingsValue is not null)
{
writer.WritePropertyName("runtime_mappings");
Expand Down Expand Up @@ -261,7 +271,6 @@ public FieldCapsRequestDescriptor()

public FieldCapsRequestDescriptor AllowNoIndices(bool? allowNoIndices = true) => Qs("allow_no_indices", allowNoIndices);
public FieldCapsRequestDescriptor ExpandWildcards(ICollection<Elastic.Clients.Elasticsearch.ExpandWildcard>? expandWildcards) => Qs("expand_wildcards", expandWildcards);
public FieldCapsRequestDescriptor Fields(Elastic.Clients.Elasticsearch.Fields? fields) => Qs("fields", fields);
public FieldCapsRequestDescriptor Filters(string? filters) => Qs("filters", filters);
public FieldCapsRequestDescriptor IgnoreUnavailable(bool? ignoreUnavailable = true) => Qs("ignore_unavailable", ignoreUnavailable);
public FieldCapsRequestDescriptor IncludeUnmapped(bool? includeUnmapped = true) => Qs("include_unmapped", includeUnmapped);
Expand All @@ -276,6 +285,7 @@ public FieldCapsRequestDescriptor Indices(Elastic.Clients.Elasticsearch.Indices?
private Elastic.Clients.Elasticsearch.QueryDsl.Query? IndexFilterValue { get; set; }
private QueryDsl.QueryDescriptor IndexFilterDescriptor { get; set; }
private Action<QueryDsl.QueryDescriptor> IndexFilterDescriptorAction { get; set; }
private Elastic.Clients.Elasticsearch.Fields? FieldsValue { get; set; }
private IDictionary<Elastic.Clients.Elasticsearch.Field, Elastic.Clients.Elasticsearch.Mapping.RuntimeField>? RuntimeMappingsValue { get; set; }

/// <summary>
Expand Down Expand Up @@ -305,6 +315,15 @@ public FieldCapsRequestDescriptor IndexFilter(Action<QueryDsl.QueryDescriptor> c
return Self;
}

/// <summary>
/// <para>List of fields to retrieve capabilities for. Wildcard (`*`) expressions are supported.</para>
/// </summary>
public FieldCapsRequestDescriptor Fields(Elastic.Clients.Elasticsearch.Fields? fields)
{
FieldsValue = fields;
return Self;
}

/// <summary>
/// <para>Defines ad-hoc runtime fields in the request similar to the way it is done in search requests.<br/>These fields exist only as part of the query and take precedence over fields defined with the same name in the index mappings.</para>
/// </summary>
Expand Down Expand Up @@ -333,6 +352,12 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
JsonSerializer.Serialize(writer, IndexFilterValue, options);
}

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

if (RuntimeMappingsValue is not null)
{
writer.WritePropertyName("runtime_mappings");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public override SearchRequest Read(ref Utf8JsonReader reader, Type typeToConvert

if (property == "knn")
{
variant.Knn = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.KnnQuery?>(ref reader, options);
variant.Knn = JsonSerializer.Deserialize<ICollection<Elastic.Clients.Elasticsearch.KnnQuery>?>(ref reader, options);
continue;
}

Expand Down Expand Up @@ -824,8 +824,8 @@ public SearchRequest(Elastic.Clients.Elasticsearch.Indices? indices) : base(r =>
/// <summary>
/// <para>Defines the approximate kNN search to run.</para>
/// </summary>
[JsonInclude, JsonPropertyName("knn")]
public Elastic.Clients.Elasticsearch.KnnQuery? Knn { get; set; }
[JsonInclude, JsonPropertyName("knn"), SingleOrManyCollectionConverter(typeof(Elastic.Clients.Elasticsearch.KnnQuery))]
public ICollection<Elastic.Clients.Elasticsearch.KnnQuery>? Knn { get; set; }

/// <summary>
/// <para>Minimum _score for matching documents. Documents with a lower _score are<br/>not included in the search results.</para>
Expand Down Expand Up @@ -1016,9 +1016,10 @@ public SearchRequestDescriptor<TDocument> Indices(Elastic.Clients.Elasticsearch.
private Elastic.Clients.Elasticsearch.Core.Search.Highlight? HighlightValue { get; set; }
private Core.Search.HighlightDescriptor<TDocument> HighlightDescriptor { get; set; }
private Action<Core.Search.HighlightDescriptor<TDocument>> HighlightDescriptorAction { get; set; }
private Elastic.Clients.Elasticsearch.KnnQuery? KnnValue { get; set; }
private ICollection<Elastic.Clients.Elasticsearch.KnnQuery>? KnnValue { get; set; }
private KnnQueryDescriptor<TDocument> KnnDescriptor { get; set; }
private Action<KnnQueryDescriptor<TDocument>> KnnDescriptorAction { get; set; }
private Action<KnnQueryDescriptor<TDocument>>[] KnnDescriptorActions { get; set; }
private Elastic.Clients.Elasticsearch.QueryDsl.Query? PostFilterValue { get; set; }
private QueryDsl.QueryDescriptor<TDocument> PostFilterDescriptor { get; set; }
private Action<QueryDsl.QueryDescriptor<TDocument>> PostFilterDescriptorAction { get; set; }
Expand Down Expand Up @@ -1215,10 +1216,11 @@ public SearchRequestDescriptor<TDocument> Highlight(Action<Core.Search.Highlight
/// <summary>
/// <para>Defines the approximate kNN search to run.</para>
/// </summary>
public SearchRequestDescriptor<TDocument> Knn(Elastic.Clients.Elasticsearch.KnnQuery? knn)
public SearchRequestDescriptor<TDocument> Knn(ICollection<Elastic.Clients.Elasticsearch.KnnQuery>? knn)
{
KnnDescriptor = null;
KnnDescriptorAction = null;
KnnDescriptorActions = null;
KnnValue = knn;
return Self;
}
Expand All @@ -1227,6 +1229,7 @@ public SearchRequestDescriptor<TDocument> Knn(KnnQueryDescriptor<TDocument> desc
{
KnnValue = null;
KnnDescriptorAction = null;
KnnDescriptorActions = null;
KnnDescriptor = descriptor;
return Self;
}
Expand All @@ -1235,10 +1238,20 @@ public SearchRequestDescriptor<TDocument> Knn(Action<KnnQueryDescriptor<TDocumen
{
KnnValue = null;
KnnDescriptor = null;
KnnDescriptorActions = null;
KnnDescriptorAction = configure;
return Self;
}

public SearchRequestDescriptor<TDocument> Knn(params Action<KnnQueryDescriptor<TDocument>>[] configure)
{
KnnValue = null;
KnnDescriptor = null;
KnnDescriptorAction = null;
KnnDescriptorActions = configure;
return Self;
}

public SearchRequestDescriptor<TDocument> PostFilter(Elastic.Clients.Elasticsearch.QueryDsl.Query? postFilter)
{
PostFilterDescriptor = null;
Expand Down Expand Up @@ -1725,10 +1738,23 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
writer.WritePropertyName("knn");
JsonSerializer.Serialize(writer, new KnnQueryDescriptor<TDocument>(KnnDescriptorAction), options);
}
else if (KnnDescriptorActions is not null)
{
writer.WritePropertyName("knn");
if (KnnDescriptorActions.Length > 1)
writer.WriteStartArray();
foreach (var action in KnnDescriptorActions)
{
JsonSerializer.Serialize(writer, new KnnQueryDescriptor<TDocument>(action), options);
}

if (KnnDescriptorActions.Length > 1)
writer.WriteEndArray();
}
else if (KnnValue is not null)
{
writer.WritePropertyName("knn");
JsonSerializer.Serialize(writer, KnnValue, options);
SingleOrManySerializationHelper.Serialize<Elastic.Clients.Elasticsearch.KnnQuery>(KnnValue, writer, options);
}

if (PostFilterDescriptor is not null)
Expand Down Expand Up @@ -2061,9 +2087,10 @@ public SearchRequestDescriptor Indices(Elastic.Clients.Elasticsearch.Indices? in
private Elastic.Clients.Elasticsearch.Core.Search.Highlight? HighlightValue { get; set; }
private Core.Search.HighlightDescriptor HighlightDescriptor { get; set; }
private Action<Core.Search.HighlightDescriptor> HighlightDescriptorAction { get; set; }
private Elastic.Clients.Elasticsearch.KnnQuery? KnnValue { get; set; }
private ICollection<Elastic.Clients.Elasticsearch.KnnQuery>? KnnValue { get; set; }
private KnnQueryDescriptor KnnDescriptor { get; set; }
private Action<KnnQueryDescriptor> KnnDescriptorAction { get; set; }
private Action<KnnQueryDescriptor>[] KnnDescriptorActions { get; set; }
private Elastic.Clients.Elasticsearch.QueryDsl.Query? PostFilterValue { get; set; }
private QueryDsl.QueryDescriptor PostFilterDescriptor { get; set; }
private Action<QueryDsl.QueryDescriptor> PostFilterDescriptorAction { get; set; }
Expand Down Expand Up @@ -2260,10 +2287,11 @@ public SearchRequestDescriptor Highlight(Action<Core.Search.HighlightDescriptor>
/// <summary>
/// <para>Defines the approximate kNN search to run.</para>
/// </summary>
public SearchRequestDescriptor Knn(Elastic.Clients.Elasticsearch.KnnQuery? knn)
public SearchRequestDescriptor Knn(ICollection<Elastic.Clients.Elasticsearch.KnnQuery>? knn)
{
KnnDescriptor = null;
KnnDescriptorAction = null;
KnnDescriptorActions = null;
KnnValue = knn;
return Self;
}
Expand All @@ -2272,6 +2300,7 @@ public SearchRequestDescriptor Knn(KnnQueryDescriptor descriptor)
{
KnnValue = null;
KnnDescriptorAction = null;
KnnDescriptorActions = null;
KnnDescriptor = descriptor;
return Self;
}
Expand All @@ -2280,10 +2309,20 @@ public SearchRequestDescriptor Knn(Action<KnnQueryDescriptor> configure)
{
KnnValue = null;
KnnDescriptor = null;
KnnDescriptorActions = null;
KnnDescriptorAction = configure;
return Self;
}

public SearchRequestDescriptor Knn(params Action<KnnQueryDescriptor>[] configure)
{
KnnValue = null;
KnnDescriptor = null;
KnnDescriptorAction = null;
KnnDescriptorActions = configure;
return Self;
}

public SearchRequestDescriptor PostFilter(Elastic.Clients.Elasticsearch.QueryDsl.Query? postFilter)
{
PostFilterDescriptor = null;
Expand Down Expand Up @@ -2770,10 +2809,23 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
writer.WritePropertyName("knn");
JsonSerializer.Serialize(writer, new KnnQueryDescriptor(KnnDescriptorAction), options);
}
else if (KnnDescriptorActions is not null)
{
writer.WritePropertyName("knn");
if (KnnDescriptorActions.Length > 1)
writer.WriteStartArray();
foreach (var action in KnnDescriptorActions)
{
JsonSerializer.Serialize(writer, new KnnQueryDescriptor(action), options);
}

if (KnnDescriptorActions.Length > 1)
writer.WriteEndArray();
}
else if (KnnValue is not null)
{
writer.WritePropertyName("knn");
JsonSerializer.Serialize(writer, KnnValue, options);
SingleOrManySerializationHelper.Serialize<Elastic.Clients.Elasticsearch.KnnQuery>(KnnValue, writer, options);
}

if (PostFilterDescriptor is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public sealed partial class QueryRequest : PlainRequest<QueryRequestParameters>
/// </summary>
[JsonInclude, JsonPropertyName("catalog")]
public string? Catalog { get; set; }

/// <summary>
/// <para>If true, the results in a columnar fashion: one row represents all the values of a certain column from the current page of results.</para>
/// </summary>
[JsonInclude, JsonPropertyName("columnar")]
public bool? Columnar { get; set; }
[JsonInclude, JsonPropertyName("cursor")]
Expand Down Expand Up @@ -205,6 +209,9 @@ public QueryRequestDescriptor<TDocument> Catalog(string? catalog)
return Self;
}

/// <summary>
/// <para>If true, the results in a columnar fashion: one row represents all the values of a certain column from the current page of results.</para>
/// </summary>
public QueryRequestDescriptor<TDocument> Columnar(bool? columnar = true)
{
ColumnarValue = columnar;
Expand Down Expand Up @@ -510,6 +517,9 @@ public QueryRequestDescriptor Catalog(string? catalog)
return Self;
}

/// <summary>
/// <para>If true, the results in a columnar fashion: one row represents all the values of a certain column from the current page of results.</para>
/// </summary>
public QueryRequestDescriptor Columnar(bool? columnar = true)
{
ColumnarValue = columnar;
Expand Down
Loading