Skip to content

Commit 8dd94ed

Browse files
Regenerate with latest spec fixes for 8.7 (#7684) (#7692)
Co-authored-by: Steve Gordon <[email protected]>
1 parent f8f225a commit 8dd94ed

File tree

10 files changed

+259
-42
lines changed

10 files changed

+259
-42
lines changed

src/Elastic.Clients.Elasticsearch/Serialization/Stringified.cs

+53
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,59 @@ public static long ReadStringifiedLong(ref Utf8JsonReader reader)
3232
}
3333

3434
return reader.GetInt64();
35+
}
36+
}
37+
38+
internal sealed class StringifiedIntegerConverter : JsonConverter<int?>
39+
{
40+
public override int? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => ReadStringifiedInteger(ref reader);
41+
42+
public override void Write(Utf8JsonWriter writer, int? value, JsonSerializerOptions options) => writer.WriteNumberValue(value.Value);
43+
44+
public static int ReadStringifiedInteger(ref Utf8JsonReader reader)
45+
{
46+
if (reader.TokenType == JsonTokenType.PropertyName)
47+
reader.Read();
48+
49+
if (reader.TokenType == JsonTokenType.String)
50+
{
51+
var intString = reader.GetString();
52+
53+
if (!int.TryParse(intString, out var intValue))
54+
{
55+
throw new JsonException("Unable to parse string value to integer.");
56+
}
57+
58+
return intValue;
59+
}
3560

61+
return reader.GetInt32();
3662
}
3763
}
64+
65+
internal sealed class StringifiedBoolConverter : JsonConverter<bool?>
66+
{
67+
public override bool? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => ReadStringifiedBool(ref reader);
68+
69+
public override void Write(Utf8JsonWriter writer, bool? value, JsonSerializerOptions options) => writer.WriteBooleanValue(value.Value);
70+
71+
public static bool ReadStringifiedBool(ref Utf8JsonReader reader)
72+
{
73+
if (reader.TokenType == JsonTokenType.PropertyName)
74+
reader.Read();
75+
76+
if (reader.TokenType == JsonTokenType.String)
77+
{
78+
var boolString = reader.GetString();
79+
80+
if (!bool.TryParse(boolString, out var boolValue))
81+
{
82+
throw new JsonException("Unable to parse string value to bool.");
83+
}
84+
85+
return boolValue;
86+
}
87+
88+
return reader.GetBoolean();
89+
}
90+
}

src/Elastic.Clients.Elasticsearch/_Generated/Api/AsyncSearch/SubmitAsyncSearchRequest.g.cs

+61-9
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public override SubmitAsyncSearchRequest Read(ref Utf8JsonReader reader, Type ty
240240

241241
if (property == "knn")
242242
{
243-
variant.Knn = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.KnnQuery?>(ref reader, options);
243+
variant.Knn = JsonSerializer.Deserialize<ICollection<Elastic.Clients.Elasticsearch.KnnQuery>?>(ref reader, options);
244244
continue;
245245
}
246246

@@ -817,8 +817,8 @@ public SubmitAsyncSearchRequest(Elastic.Clients.Elasticsearch.Indices? indices)
817817
/// <summary>
818818
/// <para>Defines the approximate kNN search to run.</para>
819819
/// </summary>
820-
[JsonInclude, JsonPropertyName("knn")]
821-
public Elastic.Clients.Elasticsearch.KnnQuery? Knn { get; set; }
820+
[JsonInclude, JsonPropertyName("knn"), SingleOrManyCollectionConverter(typeof(Elastic.Clients.Elasticsearch.KnnQuery))]
821+
public ICollection<Elastic.Clients.Elasticsearch.KnnQuery>? Knn { get; set; }
822822

823823
/// <summary>
824824
/// <para>Minimum _score for matching documents. Documents with a lower _score are<br/>not included in the search results.</para>
@@ -998,9 +998,10 @@ public SubmitAsyncSearchRequestDescriptor<TDocument> Indices(Elastic.Clients.Ela
998998
private Elastic.Clients.Elasticsearch.Core.Search.Highlight? HighlightValue { get; set; }
999999
private Core.Search.HighlightDescriptor<TDocument> HighlightDescriptor { get; set; }
10001000
private Action<Core.Search.HighlightDescriptor<TDocument>> HighlightDescriptorAction { get; set; }
1001-
private Elastic.Clients.Elasticsearch.KnnQuery? KnnValue { get; set; }
1001+
private ICollection<Elastic.Clients.Elasticsearch.KnnQuery>? KnnValue { get; set; }
10021002
private KnnQueryDescriptor<TDocument> KnnDescriptor { get; set; }
10031003
private Action<KnnQueryDescriptor<TDocument>> KnnDescriptorAction { get; set; }
1004+
private Action<KnnQueryDescriptor<TDocument>>[] KnnDescriptorActions { get; set; }
10041005
private Elastic.Clients.Elasticsearch.QueryDsl.Query? PostFilterValue { get; set; }
10051006
private QueryDsl.QueryDescriptor<TDocument> PostFilterDescriptor { get; set; }
10061007
private Action<QueryDsl.QueryDescriptor<TDocument>> PostFilterDescriptorAction { get; set; }
@@ -1197,10 +1198,11 @@ public SubmitAsyncSearchRequestDescriptor<TDocument> Highlight(Action<Core.Searc
11971198
/// <summary>
11981199
/// <para>Defines the approximate kNN search to run.</para>
11991200
/// </summary>
1200-
public SubmitAsyncSearchRequestDescriptor<TDocument> Knn(Elastic.Clients.Elasticsearch.KnnQuery? knn)
1201+
public SubmitAsyncSearchRequestDescriptor<TDocument> Knn(ICollection<Elastic.Clients.Elasticsearch.KnnQuery>? knn)
12011202
{
12021203
KnnDescriptor = null;
12031204
KnnDescriptorAction = null;
1205+
KnnDescriptorActions = null;
12041206
KnnValue = knn;
12051207
return Self;
12061208
}
@@ -1209,6 +1211,7 @@ public SubmitAsyncSearchRequestDescriptor<TDocument> Knn(KnnQueryDescriptor<TDoc
12091211
{
12101212
KnnValue = null;
12111213
KnnDescriptorAction = null;
1214+
KnnDescriptorActions = null;
12121215
KnnDescriptor = descriptor;
12131216
return Self;
12141217
}
@@ -1217,10 +1220,20 @@ public SubmitAsyncSearchRequestDescriptor<TDocument> Knn(Action<KnnQueryDescript
12171220
{
12181221
KnnValue = null;
12191222
KnnDescriptor = null;
1223+
KnnDescriptorActions = null;
12201224
KnnDescriptorAction = configure;
12211225
return Self;
12221226
}
12231227

1228+
public SubmitAsyncSearchRequestDescriptor<TDocument> Knn(params Action<KnnQueryDescriptor<TDocument>>[] configure)
1229+
{
1230+
KnnValue = null;
1231+
KnnDescriptor = null;
1232+
KnnDescriptorAction = null;
1233+
KnnDescriptorActions = configure;
1234+
return Self;
1235+
}
1236+
12241237
public SubmitAsyncSearchRequestDescriptor<TDocument> PostFilter(Elastic.Clients.Elasticsearch.QueryDsl.Query? postFilter)
12251238
{
12261239
PostFilterDescriptor = null;
@@ -1707,10 +1720,23 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
17071720
writer.WritePropertyName("knn");
17081721
JsonSerializer.Serialize(writer, new KnnQueryDescriptor<TDocument>(KnnDescriptorAction), options);
17091722
}
1723+
else if (KnnDescriptorActions is not null)
1724+
{
1725+
writer.WritePropertyName("knn");
1726+
if (KnnDescriptorActions.Length > 1)
1727+
writer.WriteStartArray();
1728+
foreach (var action in KnnDescriptorActions)
1729+
{
1730+
JsonSerializer.Serialize(writer, new KnnQueryDescriptor<TDocument>(action), options);
1731+
}
1732+
1733+
if (KnnDescriptorActions.Length > 1)
1734+
writer.WriteEndArray();
1735+
}
17101736
else if (KnnValue is not null)
17111737
{
17121738
writer.WritePropertyName("knn");
1713-
JsonSerializer.Serialize(writer, KnnValue, options);
1739+
SingleOrManySerializationHelper.Serialize<Elastic.Clients.Elasticsearch.KnnQuery>(KnnValue, writer, options);
17141740
}
17151741

17161742
if (PostFilterDescriptor is not null)
@@ -2042,9 +2068,10 @@ public SubmitAsyncSearchRequestDescriptor Indices(Elastic.Clients.Elasticsearch.
20422068
private Elastic.Clients.Elasticsearch.Core.Search.Highlight? HighlightValue { get; set; }
20432069
private Core.Search.HighlightDescriptor HighlightDescriptor { get; set; }
20442070
private Action<Core.Search.HighlightDescriptor> HighlightDescriptorAction { get; set; }
2045-
private Elastic.Clients.Elasticsearch.KnnQuery? KnnValue { get; set; }
2071+
private ICollection<Elastic.Clients.Elasticsearch.KnnQuery>? KnnValue { get; set; }
20462072
private KnnQueryDescriptor KnnDescriptor { get; set; }
20472073
private Action<KnnQueryDescriptor> KnnDescriptorAction { get; set; }
2074+
private Action<KnnQueryDescriptor>[] KnnDescriptorActions { get; set; }
20482075
private Elastic.Clients.Elasticsearch.QueryDsl.Query? PostFilterValue { get; set; }
20492076
private QueryDsl.QueryDescriptor PostFilterDescriptor { get; set; }
20502077
private Action<QueryDsl.QueryDescriptor> PostFilterDescriptorAction { get; set; }
@@ -2241,10 +2268,11 @@ public SubmitAsyncSearchRequestDescriptor Highlight(Action<Core.Search.Highlight
22412268
/// <summary>
22422269
/// <para>Defines the approximate kNN search to run.</para>
22432270
/// </summary>
2244-
public SubmitAsyncSearchRequestDescriptor Knn(Elastic.Clients.Elasticsearch.KnnQuery? knn)
2271+
public SubmitAsyncSearchRequestDescriptor Knn(ICollection<Elastic.Clients.Elasticsearch.KnnQuery>? knn)
22452272
{
22462273
KnnDescriptor = null;
22472274
KnnDescriptorAction = null;
2275+
KnnDescriptorActions = null;
22482276
KnnValue = knn;
22492277
return Self;
22502278
}
@@ -2253,6 +2281,7 @@ public SubmitAsyncSearchRequestDescriptor Knn(KnnQueryDescriptor descriptor)
22532281
{
22542282
KnnValue = null;
22552283
KnnDescriptorAction = null;
2284+
KnnDescriptorActions = null;
22562285
KnnDescriptor = descriptor;
22572286
return Self;
22582287
}
@@ -2261,10 +2290,20 @@ public SubmitAsyncSearchRequestDescriptor Knn(Action<KnnQueryDescriptor> configu
22612290
{
22622291
KnnValue = null;
22632292
KnnDescriptor = null;
2293+
KnnDescriptorActions = null;
22642294
KnnDescriptorAction = configure;
22652295
return Self;
22662296
}
22672297

2298+
public SubmitAsyncSearchRequestDescriptor Knn(params Action<KnnQueryDescriptor>[] configure)
2299+
{
2300+
KnnValue = null;
2301+
KnnDescriptor = null;
2302+
KnnDescriptorAction = null;
2303+
KnnDescriptorActions = configure;
2304+
return Self;
2305+
}
2306+
22682307
public SubmitAsyncSearchRequestDescriptor PostFilter(Elastic.Clients.Elasticsearch.QueryDsl.Query? postFilter)
22692308
{
22702309
PostFilterDescriptor = null;
@@ -2751,10 +2790,23 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
27512790
writer.WritePropertyName("knn");
27522791
JsonSerializer.Serialize(writer, new KnnQueryDescriptor(KnnDescriptorAction), options);
27532792
}
2793+
else if (KnnDescriptorActions is not null)
2794+
{
2795+
writer.WritePropertyName("knn");
2796+
if (KnnDescriptorActions.Length > 1)
2797+
writer.WriteStartArray();
2798+
foreach (var action in KnnDescriptorActions)
2799+
{
2800+
JsonSerializer.Serialize(writer, new KnnQueryDescriptor(action), options);
2801+
}
2802+
2803+
if (KnnDescriptorActions.Length > 1)
2804+
writer.WriteEndArray();
2805+
}
27542806
else if (KnnValue is not null)
27552807
{
27562808
writer.WritePropertyName("knn");
2757-
JsonSerializer.Serialize(writer, KnnValue, options);
2809+
SingleOrManySerializationHelper.Serialize<Elastic.Clients.Elasticsearch.KnnQuery>(KnnValue, writer, options);
27582810
}
27592811

27602812
if (PostFilterDescriptor is not null)

src/Elastic.Clients.Elasticsearch/_Generated/Types/Analysis/LimitTokenCountTokenFilter.g.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public sealed partial class LimitTokenCountTokenFilter : ITokenFilter
3232
[JsonInclude, JsonPropertyName("consume_all_tokens")]
3333
public bool? ConsumeAllTokens { get; set; }
3434
[JsonInclude, JsonPropertyName("max_token_count")]
35+
[JsonConverter(typeof(StringifiedIntegerConverter))]
3536
public int? MaxTokenCount { get; set; }
3637

3738
[JsonInclude, JsonPropertyName("type")]
@@ -80,10 +81,10 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
8081
writer.WriteBooleanValue(ConsumeAllTokensValue.Value);
8182
}
8283

83-
if (MaxTokenCountValue.HasValue)
84+
if (MaxTokenCountValue is not null)
8485
{
8586
writer.WritePropertyName("max_token_count");
86-
writer.WriteNumberValue(MaxTokenCountValue.Value);
87+
JsonSerializer.Serialize(writer, MaxTokenCountValue, options);
8788
}
8889

8990
writer.WritePropertyName("type");

src/Elastic.Clients.Elasticsearch/_Generated/Types/Analysis/StemmerTokenFilter.g.cs

+60-7
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,64 @@
2727

2828
namespace Elastic.Clients.Elasticsearch.Analysis;
2929

30+
internal sealed partial class StemmerTokenFilterConverter : JsonConverter<StemmerTokenFilter>
31+
{
32+
public override StemmerTokenFilter Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
33+
{
34+
if (reader.TokenType != JsonTokenType.StartObject)
35+
throw new JsonException("Unexpected JSON detected.");
36+
var variant = new StemmerTokenFilter();
37+
while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
38+
{
39+
if (reader.TokenType == JsonTokenType.PropertyName)
40+
{
41+
var property = reader.GetString();
42+
if (property == "language" || property == "name")
43+
{
44+
variant.Language = JsonSerializer.Deserialize<string?>(ref reader, options);
45+
continue;
46+
}
47+
48+
if (property == "version")
49+
{
50+
variant.Version = JsonSerializer.Deserialize<string?>(ref reader, options);
51+
continue;
52+
}
53+
}
54+
}
55+
56+
return variant;
57+
}
58+
59+
public override void Write(Utf8JsonWriter writer, StemmerTokenFilter value, JsonSerializerOptions options)
60+
{
61+
writer.WriteStartObject();
62+
if (!string.IsNullOrEmpty(value.Language))
63+
{
64+
writer.WritePropertyName("language");
65+
writer.WriteStringValue(value.Language);
66+
}
67+
68+
writer.WritePropertyName("type");
69+
writer.WriteStringValue("stemmer");
70+
if (value.Version is not null)
71+
{
72+
writer.WritePropertyName("version");
73+
JsonSerializer.Serialize(writer, value.Version, options);
74+
}
75+
76+
writer.WriteEndObject();
77+
}
78+
}
79+
80+
[JsonConverter(typeof(StemmerTokenFilterConverter))]
3081
public sealed partial class StemmerTokenFilter : ITokenFilter
3182
{
32-
[JsonInclude, JsonPropertyName("language")]
33-
public string Language { get; set; }
83+
public string? Language { get; set; }
3484

3585
[JsonInclude, JsonPropertyName("type")]
3686
public string Type => "stemmer";
3787

38-
[JsonInclude, JsonPropertyName("version")]
3988
public string? Version { get; set; }
4089
}
4190

@@ -47,10 +96,10 @@ public StemmerTokenFilterDescriptor() : base()
4796
{
4897
}
4998

50-
private string LanguageValue { get; set; }
99+
private string? LanguageValue { get; set; }
51100
private string? VersionValue { get; set; }
52101

53-
public StemmerTokenFilterDescriptor Language(string language)
102+
public StemmerTokenFilterDescriptor Language(string? language)
54103
{
55104
LanguageValue = language;
56105
return Self;
@@ -65,8 +114,12 @@ public StemmerTokenFilterDescriptor Version(string? version)
65114
protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
66115
{
67116
writer.WriteStartObject();
68-
writer.WritePropertyName("language");
69-
writer.WriteStringValue(LanguageValue);
117+
if (!string.IsNullOrEmpty(LanguageValue))
118+
{
119+
writer.WritePropertyName("language");
120+
writer.WriteStringValue(LanguageValue);
121+
}
122+
70123
writer.WritePropertyName("type");
71124
writer.WriteStringValue("stemmer");
72125
if (VersionValue is not null)

0 commit comments

Comments
 (0)