Skip to content

Commit 4327ba8

Browse files
[9.0] Set typed_keys to true by default (#8609) (#8611)
Co-authored-by: Florian Bernd <[email protected]>
1 parent bcfff12 commit 4327ba8

File tree

9 files changed

+70
-7
lines changed

9 files changed

+70
-7
lines changed

src/Elastic.Clients.Elasticsearch/_Shared/Api/AsyncSearch/GetAsyncSearchRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ public partial class GetAsyncSearchRequest
88
{
99
// Any request may contain aggregations so we force `typed_keys` in order to successfully
1010
// deserialize them.
11-
internal override void BeforeRequest() => TypedKeys = true;
11+
internal override void BeforeRequest() => TypedKeys ??= true;
1212
}

src/Elastic.Clients.Elasticsearch/_Shared/Api/AsyncSearch/SubmitAsyncSearchRequest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ namespace Elastic.Clients.Elasticsearch.AsyncSearch;
99

1010
public partial class SubmitAsyncSearchRequest
1111
{
12-
// Any request may contain aggregations so we force typed_keys in order to successfully deserialize them.
13-
internal override void BeforeRequest() => TypedKeys = true;
12+
// Any request may contain aggregations so we force `typed_keys` in order to successfully
13+
// // deserialize them.
14+
internal override void BeforeRequest() => TypedKeys ??= true;
1415
}
1516

1617
public readonly partial struct SubmitAsyncSearchRequestDescriptor

src/Elastic.Clients.Elasticsearch/_Shared/Api/MultiSearchRequest.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ public partial class MultiSearchResponse<TDocument>
2222

2323
public partial class MultiSearchRequest : IStreamSerializable
2424
{
25-
internal override void BeforeRequest() => TypedKeys = true;
25+
// Any request may contain aggregations so we force `typed_keys` in order to successfully
26+
// deserialize them.
27+
internal override void BeforeRequest()
28+
{
29+
if (Searches.Any(x => x.Body.Aggregations is { Count: > 0 } || x.Body.Suggest is { Suggesters: { Count: > 0 } }))
30+
{
31+
TypedKeys ??= true;
32+
}
33+
}
2634

2735
void IStreamSerializable.Serialize(Stream stream, IElasticsearchClientSettings settings, SerializationFormatting formatting)
2836
{

src/Elastic.Clients.Elasticsearch/_Shared/Api/MultiSearchTemplateRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public partial class MultiSearchTemplateResponse<TDocument>
2222

2323
public partial class MultiSearchTemplateRequest : IStreamSerializable
2424
{
25-
internal override void BeforeRequest() => TypedKeys = true;
25+
internal override void BeforeRequest() => TypedKeys ??= true;
2626

2727
void IStreamSerializable.Serialize(Stream stream, IElasticsearchClientSettings settings, SerializationFormatting formatting)
2828
{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Elastic.Clients.Elasticsearch.Rollup;
6+
7+
public partial class RollupSearchRequest
8+
{
9+
// Any request may contain aggregations so we force `typed_keys` in order to successfully
10+
// deserialize them.
11+
internal override void BeforeRequest() => TypedKeys ??= true;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Elastic.Clients.Elasticsearch.SearchApplication;
6+
7+
public partial class SearchApplicationSearchRequest
8+
{
9+
// Any request may contain aggregations so we force `typed_keys` in order to successfully
10+
// deserialize them.
11+
internal override void BeforeRequest() => TypedKeys ??= true;
12+
}

src/Elastic.Clients.Elasticsearch/_Shared/Api/SearchRequest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public partial class SearchRequest
1616
{
1717
internal override void BeforeRequest()
1818
{
19-
if (Aggregations is not null || Suggest is not null)
19+
if (Aggregations is { Count: > 0 } || Suggest is { Suggesters: { Count: > 0 } })
2020
{
21-
TypedKeys = true;
21+
TypedKeys ??= true;
2222
}
2323
}
2424

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Elastic.Clients.Elasticsearch;
6+
7+
public partial class SearchTemplateRequest
8+
{
9+
// Any request may contain aggregations so we force `typed_keys` in order to successfully
10+
// deserialize them.
11+
internal override void BeforeRequest() => TypedKeys ??= true;
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Elastic.Clients.Elasticsearch.Security;
6+
7+
public partial class QueryApiKeysRequest
8+
{
9+
// Any request may contain aggregations so we force `typed_keys` in order to successfully
10+
// deserialize them.
11+
internal override void BeforeRequest()
12+
{
13+
if (Aggregations is { Count: > 0 })
14+
{
15+
TypedKeys ??= true;
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)