diff --git a/src/Elastic.Clients.Elasticsearch/_Shared/Api/AsyncSearch/GetAsyncSearchRequest.cs b/src/Elastic.Clients.Elasticsearch/_Shared/Api/AsyncSearch/GetAsyncSearchRequest.cs index 17d06d6e72a..99ea121a394 100644 --- a/src/Elastic.Clients.Elasticsearch/_Shared/Api/AsyncSearch/GetAsyncSearchRequest.cs +++ b/src/Elastic.Clients.Elasticsearch/_Shared/Api/AsyncSearch/GetAsyncSearchRequest.cs @@ -8,5 +8,5 @@ public partial class GetAsyncSearchRequest { // Any request may contain aggregations so we force `typed_keys` in order to successfully // deserialize them. - internal override void BeforeRequest() => TypedKeys = true; + internal override void BeforeRequest() => TypedKeys ??= true; } diff --git a/src/Elastic.Clients.Elasticsearch/_Shared/Api/AsyncSearch/SubmitAsyncSearchRequest.cs b/src/Elastic.Clients.Elasticsearch/_Shared/Api/AsyncSearch/SubmitAsyncSearchRequest.cs index d12357c844c..c9eb803e0c4 100644 --- a/src/Elastic.Clients.Elasticsearch/_Shared/Api/AsyncSearch/SubmitAsyncSearchRequest.cs +++ b/src/Elastic.Clients.Elasticsearch/_Shared/Api/AsyncSearch/SubmitAsyncSearchRequest.cs @@ -9,8 +9,9 @@ namespace Elastic.Clients.Elasticsearch.AsyncSearch; public partial class SubmitAsyncSearchRequest { - // Any request may contain aggregations so we force typed_keys in order to successfully deserialize them. - internal override void BeforeRequest() => TypedKeys = true; + // Any request may contain aggregations so we force `typed_keys` in order to successfully + // // deserialize them. + internal override void BeforeRequest() => TypedKeys ??= true; } public readonly partial struct SubmitAsyncSearchRequestDescriptor diff --git a/src/Elastic.Clients.Elasticsearch/_Shared/Api/MultiSearchRequest.cs b/src/Elastic.Clients.Elasticsearch/_Shared/Api/MultiSearchRequest.cs index 4ec8f52cd77..b77494a7cd5 100644 --- a/src/Elastic.Clients.Elasticsearch/_Shared/Api/MultiSearchRequest.cs +++ b/src/Elastic.Clients.Elasticsearch/_Shared/Api/MultiSearchRequest.cs @@ -22,7 +22,15 @@ public partial class MultiSearchResponse public partial class MultiSearchRequest : IStreamSerializable { - internal override void BeforeRequest() => TypedKeys = true; + // Any request may contain aggregations so we force `typed_keys` in order to successfully + // deserialize them. + internal override void BeforeRequest() + { + if (Searches.Any(x => x.Body.Aggregations is { Count: > 0 } || x.Body.Suggest is { Suggesters: { Count: > 0 } })) + { + TypedKeys ??= true; + } + } void IStreamSerializable.Serialize(Stream stream, IElasticsearchClientSettings settings, SerializationFormatting formatting) { diff --git a/src/Elastic.Clients.Elasticsearch/_Shared/Api/MultiSearchTemplateRequest.cs b/src/Elastic.Clients.Elasticsearch/_Shared/Api/MultiSearchTemplateRequest.cs index 131a29d81c3..5eb4fa8c398 100644 --- a/src/Elastic.Clients.Elasticsearch/_Shared/Api/MultiSearchTemplateRequest.cs +++ b/src/Elastic.Clients.Elasticsearch/_Shared/Api/MultiSearchTemplateRequest.cs @@ -22,7 +22,7 @@ public partial class MultiSearchTemplateResponse public partial class MultiSearchTemplateRequest : IStreamSerializable { - internal override void BeforeRequest() => TypedKeys = true; + internal override void BeforeRequest() => TypedKeys ??= true; void IStreamSerializable.Serialize(Stream stream, IElasticsearchClientSettings settings, SerializationFormatting formatting) { diff --git a/src/Elastic.Clients.Elasticsearch/_Shared/Api/Rollup/RollupSearchRequest.cs b/src/Elastic.Clients.Elasticsearch/_Shared/Api/Rollup/RollupSearchRequest.cs new file mode 100644 index 00000000000..92a67abe28d --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Shared/Api/Rollup/RollupSearchRequest.cs @@ -0,0 +1,12 @@ +// 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. + +namespace Elastic.Clients.Elasticsearch.Rollup; + +public partial class RollupSearchRequest +{ + // Any request may contain aggregations so we force `typed_keys` in order to successfully + // deserialize them. + internal override void BeforeRequest() => TypedKeys ??= true; +} diff --git a/src/Elastic.Clients.Elasticsearch/_Shared/Api/SearchApplication/RollupSearchRequest.cs b/src/Elastic.Clients.Elasticsearch/_Shared/Api/SearchApplication/RollupSearchRequest.cs new file mode 100644 index 00000000000..199d21f260a --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Shared/Api/SearchApplication/RollupSearchRequest.cs @@ -0,0 +1,12 @@ +// 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. + +namespace Elastic.Clients.Elasticsearch.SearchApplication; + +public partial class SearchApplicationSearchRequest +{ + // Any request may contain aggregations so we force `typed_keys` in order to successfully + // deserialize them. + internal override void BeforeRequest() => TypedKeys ??= true; +} diff --git a/src/Elastic.Clients.Elasticsearch/_Shared/Api/SearchRequest.cs b/src/Elastic.Clients.Elasticsearch/_Shared/Api/SearchRequest.cs index 2092393e197..56383386fa1 100644 --- a/src/Elastic.Clients.Elasticsearch/_Shared/Api/SearchRequest.cs +++ b/src/Elastic.Clients.Elasticsearch/_Shared/Api/SearchRequest.cs @@ -16,9 +16,9 @@ public partial class SearchRequest { internal override void BeforeRequest() { - if (Aggregations is not null || Suggest is not null) + if (Aggregations is { Count: > 0 } || Suggest is { Suggesters: { Count: > 0 } }) { - TypedKeys = true; + TypedKeys ??= true; } } diff --git a/src/Elastic.Clients.Elasticsearch/_Shared/Api/SearchTemplateRequest.cs b/src/Elastic.Clients.Elasticsearch/_Shared/Api/SearchTemplateRequest.cs new file mode 100644 index 00000000000..b6de1acb784 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Shared/Api/SearchTemplateRequest.cs @@ -0,0 +1,12 @@ +// 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. + +namespace Elastic.Clients.Elasticsearch; + +public partial class SearchTemplateRequest +{ + // Any request may contain aggregations so we force `typed_keys` in order to successfully + // deserialize them. + internal override void BeforeRequest() => TypedKeys ??= true; +} diff --git a/src/Elastic.Clients.Elasticsearch/_Shared/Api/Security/QueryApiKeysRequest.cs b/src/Elastic.Clients.Elasticsearch/_Shared/Api/Security/QueryApiKeysRequest.cs new file mode 100644 index 00000000000..ab80bc509b6 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Shared/Api/Security/QueryApiKeysRequest.cs @@ -0,0 +1,18 @@ +// 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. + +namespace Elastic.Clients.Elasticsearch.Security; + +public partial class QueryApiKeysRequest +{ + // Any request may contain aggregations so we force `typed_keys` in order to successfully + // deserialize them. + internal override void BeforeRequest() + { + if (Aggregations is { Count: > 0 }) + { + TypedKeys ??= true; + } + } +}