diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/AsyncSearch/AsyncSearchSubmitRequest.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/AsyncSearch/AsyncSearchSubmitRequest.g.cs index 6d7c730e6a2..f285242daa0 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Api/AsyncSearch/AsyncSearchSubmitRequest.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/AsyncSearch/AsyncSearchSubmitRequest.g.cs @@ -124,6 +124,391 @@ public sealed class AsyncSearchSubmitRequestParameters : RequestParameters Q("q"); set => Q("q", value); } } + internal sealed class AsyncSearchSubmitRequestConverter : JsonConverter + { + public override AsyncSearchSubmitRequest Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new AsyncSearchSubmitRequest(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "aggregations" || property == "aggs") + { + variant.Aggregations = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "collapse") + { + variant.Collapse = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "explain") + { + variant.Explain = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "from") + { + variant.From = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "highlight") + { + variant.Highlight = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "track_total_hits") + { + variant.TrackTotalHits = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "indices_boost") + { + variant.IndicesBoost = JsonSerializer.Deserialize>?>(ref reader, options); + continue; + } + + if (property == "docvalue_fields") + { + variant.DocvalueFields = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "min_score") + { + variant.MinScore = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "post_filter") + { + variant.PostFilter = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "profile") + { + variant.Profile = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "query") + { + variant.Query = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "rescore") + { + variant.Rescore = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "script_fields") + { + variant.ScriptFields = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "search_after") + { + variant.SearchAfter = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "size") + { + variant.Size = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "slice") + { + variant.Slice = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "sort") + { + variant.Sort = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "_source") + { + variant.Source = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "fields") + { + variant.Fields = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "suggest") + { + variant.Suggest = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "terminate_after") + { + variant.TerminateAfter = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "timeout") + { + variant.Timeout = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "track_scores") + { + variant.TrackScores = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "version") + { + variant.Version = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "seq_no_primary_term") + { + variant.SeqNoPrimaryTerm = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "stored_fields") + { + variant.StoredFields = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "pit") + { + variant.Pit = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "runtime_mappings") + { + variant.RuntimeMappings = JsonSerializer.Deserialize>?>(ref reader, options); + continue; + } + + if (property == "stats") + { + variant.Stats = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + } + } + + return variant; + } + + public override void Write(Utf8JsonWriter writer, AsyncSearchSubmitRequest value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Aggregations is not null) + { + writer.WritePropertyName("aggregations"); + JsonSerializer.Serialize(writer, value.Aggregations, options); + } + + if (value.Collapse is not null) + { + writer.WritePropertyName("collapse"); + JsonSerializer.Serialize(writer, value.Collapse, options); + } + + if (value.Explain.HasValue) + { + writer.WritePropertyName("explain"); + writer.WriteBooleanValue(value.Explain.Value); + } + + if (value.From.HasValue) + { + writer.WritePropertyName("from"); + writer.WriteNumberValue(value.From.Value); + } + + if (value.Highlight is not null) + { + writer.WritePropertyName("highlight"); + JsonSerializer.Serialize(writer, value.Highlight, options); + } + + if (value.TrackTotalHits is not null) + { + writer.WritePropertyName("track_total_hits"); + JsonSerializer.Serialize(writer, value.TrackTotalHits, options); + } + + if (value.IndicesBoost is not null) + { + writer.WritePropertyName("indices_boost"); + JsonSerializer.Serialize(writer, value.IndicesBoost, options); + } + + if (value.DocvalueFields is not null) + { + writer.WritePropertyName("docvalue_fields"); + JsonSerializer.Serialize(writer, value.DocvalueFields, options); + } + + if (value.MinScore.HasValue) + { + writer.WritePropertyName("min_score"); + writer.WriteNumberValue(value.MinScore.Value); + } + + if (value.PostFilter is not null) + { + writer.WritePropertyName("post_filter"); + JsonSerializer.Serialize(writer, value.PostFilter, options); + } + + if (value.Profile.HasValue) + { + writer.WritePropertyName("profile"); + writer.WriteBooleanValue(value.Profile.Value); + } + + if (value.Query is not null) + { + writer.WritePropertyName("query"); + JsonSerializer.Serialize(writer, value.Query, options); + } + + if (value.Rescore is not null) + { + writer.WritePropertyName("rescore"); + JsonSerializer.Serialize(writer, value.Rescore, options); + } + + if (value.ScriptFields is not null) + { + writer.WritePropertyName("script_fields"); + JsonSerializer.Serialize(writer, value.ScriptFields, options); + } + + if (value.SearchAfter is not null) + { + writer.WritePropertyName("search_after"); + JsonSerializer.Serialize(writer, value.SearchAfter, options); + } + + if (value.Size.HasValue) + { + writer.WritePropertyName("size"); + writer.WriteNumberValue(value.Size.Value); + } + + if (value.Slice is not null) + { + writer.WritePropertyName("slice"); + JsonSerializer.Serialize(writer, value.Slice, options); + } + + if (value.Sort is not null) + { + writer.WritePropertyName("sort"); + JsonSerializer.Serialize(writer, value.Sort, options); + } + + if (value.Source is not null) + { + writer.WritePropertyName("_source"); + JsonSerializer.Serialize(writer, value.Source, options); + } + + if (value.Fields is not null) + { + writer.WritePropertyName("fields"); + JsonSerializer.Serialize(writer, value.Fields, options); + } + + if (value.Suggest is not null) + { + writer.WritePropertyName("suggest"); + JsonSerializer.Serialize(writer, value.Suggest, options); + } + + if (value.TerminateAfter.HasValue) + { + writer.WritePropertyName("terminate_after"); + writer.WriteNumberValue(value.TerminateAfter.Value); + } + + if (!string.IsNullOrEmpty(value.Timeout)) + { + writer.WritePropertyName("timeout"); + writer.WriteStringValue(value.Timeout); + } + + if (value.TrackScores.HasValue) + { + writer.WritePropertyName("track_scores"); + writer.WriteBooleanValue(value.TrackScores.Value); + } + + if (value.Version.HasValue) + { + writer.WritePropertyName("version"); + writer.WriteBooleanValue(value.Version.Value); + } + + if (value.SeqNoPrimaryTerm.HasValue) + { + writer.WritePropertyName("seq_no_primary_term"); + writer.WriteBooleanValue(value.SeqNoPrimaryTerm.Value); + } + + if (value.StoredFields is not null) + { + writer.WritePropertyName("stored_fields"); + JsonSerializer.Serialize(writer, value.StoredFields, options); + } + + if (value.Pit is not null) + { + writer.WritePropertyName("pit"); + JsonSerializer.Serialize(writer, value.Pit, options); + } + + if (value.RuntimeMappings is not null) + { + writer.WritePropertyName("runtime_mappings"); + JsonSerializer.Serialize(writer, value.RuntimeMappings, options); + } + + if (value.Stats is not null) + { + writer.WritePropertyName("stats"); + JsonSerializer.Serialize(writer, value.Stats, options); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(AsyncSearchSubmitRequestConverter))] public partial class AsyncSearchSubmitRequest : PlainRequestBase { public AsyncSearchSubmitRequest() diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/Ml/MlPutDatafeedRequest.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Ml/MlPutDatafeedRequest.g.cs index 63cce50dab3..4c178d663ca 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Api/Ml/MlPutDatafeedRequest.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Ml/MlPutDatafeedRequest.g.cs @@ -40,12 +40,209 @@ public sealed class MlPutDatafeedRequestParameters : RequestParameters Q("ignore_unavailable"); set => Q("ignore_unavailable", value); } } + internal sealed class MlPutDatafeedRequestConverter : JsonConverter + { + public override MlPutDatafeedRequest Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new MlPutDatafeedRequest(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "aggregations") + { + variant.Aggregations = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "chunking_config") + { + variant.ChunkingConfig = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "delayed_data_check_config") + { + variant.DelayedDataCheckConfig = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "frequency") + { + variant.Frequency = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "indices" || property == "indexes") + { + variant.Indices = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "indices_options") + { + variant.IndicesOptions = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "job_id") + { + variant.JobId = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "max_empty_searches") + { + variant.MaxEmptySearches = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "query") + { + variant.Query = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "query_delay") + { + variant.QueryDelay = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "runtime_mappings") + { + variant.RuntimeMappings = JsonSerializer.Deserialize>?>(ref reader, options); + continue; + } + + if (property == "script_fields") + { + variant.ScriptFields = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "scroll_size") + { + variant.ScrollSize = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "headers") + { + variant.Headers = JsonSerializer.Deserialize>?>(ref reader, options); + continue; + } + } + } + + return variant; + } + + public override void Write(Utf8JsonWriter writer, MlPutDatafeedRequest value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Aggregations is not null) + { + writer.WritePropertyName("aggregations"); + JsonSerializer.Serialize(writer, value.Aggregations, options); + } + + if (value.ChunkingConfig is not null) + { + writer.WritePropertyName("chunking_config"); + JsonSerializer.Serialize(writer, value.ChunkingConfig, options); + } + + if (value.DelayedDataCheckConfig is not null) + { + writer.WritePropertyName("delayed_data_check_config"); + JsonSerializer.Serialize(writer, value.DelayedDataCheckConfig, options); + } + + if (value.Frequency is not null) + { + writer.WritePropertyName("frequency"); + JsonSerializer.Serialize(writer, value.Frequency, options); + } + + if (value.Indices is not null) + { + writer.WritePropertyName("indices"); + JsonSerializer.Serialize(writer, value.Indices, options); + } + + if (value.IndicesOptions is not null) + { + writer.WritePropertyName("indices_options"); + JsonSerializer.Serialize(writer, value.IndicesOptions, options); + } + + if (value.JobId is not null) + { + writer.WritePropertyName("job_id"); + JsonSerializer.Serialize(writer, value.JobId, options); + } + + if (value.MaxEmptySearches.HasValue) + { + writer.WritePropertyName("max_empty_searches"); + writer.WriteNumberValue(value.MaxEmptySearches.Value); + } + + if (value.Query is not null) + { + writer.WritePropertyName("query"); + JsonSerializer.Serialize(writer, value.Query, options); + } + + if (value.QueryDelay is not null) + { + writer.WritePropertyName("query_delay"); + JsonSerializer.Serialize(writer, value.QueryDelay, options); + } + + if (value.RuntimeMappings is not null) + { + writer.WritePropertyName("runtime_mappings"); + JsonSerializer.Serialize(writer, value.RuntimeMappings, options); + } + + if (value.ScriptFields is not null) + { + writer.WritePropertyName("script_fields"); + JsonSerializer.Serialize(writer, value.ScriptFields, options); + } + + if (value.ScrollSize.HasValue) + { + writer.WritePropertyName("scroll_size"); + writer.WriteNumberValue(value.ScrollSize.Value); + } + + if (value.Headers is not null) + { + writer.WritePropertyName("headers"); + JsonSerializer.Serialize(writer, value.Headers, options); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(MlPutDatafeedRequestConverter))] public sealed partial class MlPutDatafeedRequest : PlainRequestBase { public MlPutDatafeedRequest(Elastic.Clients.Elasticsearch.Id datafeed_id) : base(r => r.Required("datafeed_id", datafeed_id)) { } + internal MlPutDatafeedRequest() + { + } + internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningPutDatafeed; protected override HttpMethod HttpMethod => HttpMethod.PUT; protected override bool SupportsBody => true; diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/Ml/MlUpdateDatafeedRequest.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Ml/MlUpdateDatafeedRequest.g.cs index 194d02c3d4e..55324716256 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Api/Ml/MlUpdateDatafeedRequest.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/Ml/MlUpdateDatafeedRequest.g.cs @@ -40,12 +40,185 @@ public sealed class MlUpdateDatafeedRequestParameters : RequestParameters Q("ignore_unavailable"); set => Q("ignore_unavailable", value); } } + internal sealed class MlUpdateDatafeedRequestConverter : JsonConverter + { + public override MlUpdateDatafeedRequest Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new MlUpdateDatafeedRequest(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "aggregations") + { + variant.Aggregations = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "chunking_config") + { + variant.ChunkingConfig = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "delayed_data_check_config") + { + variant.DelayedDataCheckConfig = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "frequency") + { + variant.Frequency = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "indices" || property == "indexes") + { + variant.Indices = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "indices_options") + { + variant.IndicesOptions = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "max_empty_searches") + { + variant.MaxEmptySearches = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "query") + { + variant.Query = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "query_delay") + { + variant.QueryDelay = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "runtime_mappings") + { + variant.RuntimeMappings = JsonSerializer.Deserialize>?>(ref reader, options); + continue; + } + + if (property == "script_fields") + { + variant.ScriptFields = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "scroll_size") + { + variant.ScrollSize = JsonSerializer.Deserialize(ref reader, options); + continue; + } + } + } + + return variant; + } + + public override void Write(Utf8JsonWriter writer, MlUpdateDatafeedRequest value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Aggregations is not null) + { + writer.WritePropertyName("aggregations"); + JsonSerializer.Serialize(writer, value.Aggregations, options); + } + + if (value.ChunkingConfig is not null) + { + writer.WritePropertyName("chunking_config"); + JsonSerializer.Serialize(writer, value.ChunkingConfig, options); + } + + if (value.DelayedDataCheckConfig is not null) + { + writer.WritePropertyName("delayed_data_check_config"); + JsonSerializer.Serialize(writer, value.DelayedDataCheckConfig, options); + } + + if (value.Frequency is not null) + { + writer.WritePropertyName("frequency"); + JsonSerializer.Serialize(writer, value.Frequency, options); + } + + if (value.Indices is not null) + { + writer.WritePropertyName("indices"); + JsonSerializer.Serialize(writer, value.Indices, options); + } + + if (value.IndicesOptions is not null) + { + writer.WritePropertyName("indices_options"); + JsonSerializer.Serialize(writer, value.IndicesOptions, options); + } + + if (value.MaxEmptySearches.HasValue) + { + writer.WritePropertyName("max_empty_searches"); + writer.WriteNumberValue(value.MaxEmptySearches.Value); + } + + if (value.Query is not null) + { + writer.WritePropertyName("query"); + JsonSerializer.Serialize(writer, value.Query, options); + } + + if (value.QueryDelay is not null) + { + writer.WritePropertyName("query_delay"); + JsonSerializer.Serialize(writer, value.QueryDelay, options); + } + + if (value.RuntimeMappings is not null) + { + writer.WritePropertyName("runtime_mappings"); + JsonSerializer.Serialize(writer, value.RuntimeMappings, options); + } + + if (value.ScriptFields is not null) + { + writer.WritePropertyName("script_fields"); + JsonSerializer.Serialize(writer, value.ScriptFields, options); + } + + if (value.ScrollSize.HasValue) + { + writer.WritePropertyName("scroll_size"); + writer.WriteNumberValue(value.ScrollSize.Value); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(MlUpdateDatafeedRequestConverter))] public sealed partial class MlUpdateDatafeedRequest : PlainRequestBase { public MlUpdateDatafeedRequest(Elastic.Clients.Elasticsearch.Id datafeed_id) : base(r => r.Required("datafeed_id", datafeed_id)) { } + internal MlUpdateDatafeedRequest() + { + } + internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningUpdateDatafeed; protected override HttpMethod HttpMethod => HttpMethod.POST; protected override bool SupportsBody => true; diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/SearchRequest.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/SearchRequest.g.cs index 1336c54c7d9..a0e5e605c8b 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Api/SearchRequest.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/SearchRequest.g.cs @@ -115,6 +115,391 @@ public sealed class SearchRequestParameters : RequestParameters Q("q"); set => Q("q", value); } } + internal sealed class SearchRequestConverter : JsonConverter + { + public override SearchRequest Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new SearchRequest(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "aggregations" || property == "aggs") + { + variant.Aggregations = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "collapse") + { + variant.Collapse = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "explain") + { + variant.Explain = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "from") + { + variant.From = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "highlight") + { + variant.Highlight = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "track_total_hits") + { + variant.TrackTotalHits = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "indices_boost") + { + variant.IndicesBoost = JsonSerializer.Deserialize>?>(ref reader, options); + continue; + } + + if (property == "docvalue_fields") + { + variant.DocvalueFields = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "min_score") + { + variant.MinScore = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "post_filter") + { + variant.PostFilter = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "profile") + { + variant.Profile = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "query") + { + variant.Query = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "rescore") + { + variant.Rescore = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "script_fields") + { + variant.ScriptFields = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "search_after") + { + variant.SearchAfter = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "size") + { + variant.Size = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "slice") + { + variant.Slice = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "sort") + { + variant.Sort = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "_source") + { + variant.Source = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "fields") + { + variant.Fields = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "suggest") + { + variant.Suggest = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "terminate_after") + { + variant.TerminateAfter = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "timeout") + { + variant.Timeout = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "track_scores") + { + variant.TrackScores = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "version") + { + variant.Version = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "seq_no_primary_term") + { + variant.SeqNoPrimaryTerm = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "stored_fields") + { + variant.StoredFields = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "pit") + { + variant.Pit = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "runtime_mappings") + { + variant.RuntimeMappings = JsonSerializer.Deserialize>?>(ref reader, options); + continue; + } + + if (property == "stats") + { + variant.Stats = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + } + } + + return variant; + } + + public override void Write(Utf8JsonWriter writer, SearchRequest value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Aggregations is not null) + { + writer.WritePropertyName("aggregations"); + JsonSerializer.Serialize(writer, value.Aggregations, options); + } + + if (value.Collapse is not null) + { + writer.WritePropertyName("collapse"); + JsonSerializer.Serialize(writer, value.Collapse, options); + } + + if (value.Explain.HasValue) + { + writer.WritePropertyName("explain"); + writer.WriteBooleanValue(value.Explain.Value); + } + + if (value.From.HasValue) + { + writer.WritePropertyName("from"); + writer.WriteNumberValue(value.From.Value); + } + + if (value.Highlight is not null) + { + writer.WritePropertyName("highlight"); + JsonSerializer.Serialize(writer, value.Highlight, options); + } + + if (value.TrackTotalHits is not null) + { + writer.WritePropertyName("track_total_hits"); + JsonSerializer.Serialize(writer, value.TrackTotalHits, options); + } + + if (value.IndicesBoost is not null) + { + writer.WritePropertyName("indices_boost"); + JsonSerializer.Serialize(writer, value.IndicesBoost, options); + } + + if (value.DocvalueFields is not null) + { + writer.WritePropertyName("docvalue_fields"); + JsonSerializer.Serialize(writer, value.DocvalueFields, options); + } + + if (value.MinScore.HasValue) + { + writer.WritePropertyName("min_score"); + writer.WriteNumberValue(value.MinScore.Value); + } + + if (value.PostFilter is not null) + { + writer.WritePropertyName("post_filter"); + JsonSerializer.Serialize(writer, value.PostFilter, options); + } + + if (value.Profile.HasValue) + { + writer.WritePropertyName("profile"); + writer.WriteBooleanValue(value.Profile.Value); + } + + if (value.Query is not null) + { + writer.WritePropertyName("query"); + JsonSerializer.Serialize(writer, value.Query, options); + } + + if (value.Rescore is not null) + { + writer.WritePropertyName("rescore"); + JsonSerializer.Serialize(writer, value.Rescore, options); + } + + if (value.ScriptFields is not null) + { + writer.WritePropertyName("script_fields"); + JsonSerializer.Serialize(writer, value.ScriptFields, options); + } + + if (value.SearchAfter is not null) + { + writer.WritePropertyName("search_after"); + JsonSerializer.Serialize(writer, value.SearchAfter, options); + } + + if (value.Size.HasValue) + { + writer.WritePropertyName("size"); + writer.WriteNumberValue(value.Size.Value); + } + + if (value.Slice is not null) + { + writer.WritePropertyName("slice"); + JsonSerializer.Serialize(writer, value.Slice, options); + } + + if (value.Sort is not null) + { + writer.WritePropertyName("sort"); + JsonSerializer.Serialize(writer, value.Sort, options); + } + + if (value.Source is not null) + { + writer.WritePropertyName("_source"); + JsonSerializer.Serialize(writer, value.Source, options); + } + + if (value.Fields is not null) + { + writer.WritePropertyName("fields"); + JsonSerializer.Serialize(writer, value.Fields, options); + } + + if (value.Suggest is not null) + { + writer.WritePropertyName("suggest"); + JsonSerializer.Serialize(writer, value.Suggest, options); + } + + if (value.TerminateAfter.HasValue) + { + writer.WritePropertyName("terminate_after"); + writer.WriteNumberValue(value.TerminateAfter.Value); + } + + if (!string.IsNullOrEmpty(value.Timeout)) + { + writer.WritePropertyName("timeout"); + writer.WriteStringValue(value.Timeout); + } + + if (value.TrackScores.HasValue) + { + writer.WritePropertyName("track_scores"); + writer.WriteBooleanValue(value.TrackScores.Value); + } + + if (value.Version.HasValue) + { + writer.WritePropertyName("version"); + writer.WriteBooleanValue(value.Version.Value); + } + + if (value.SeqNoPrimaryTerm.HasValue) + { + writer.WritePropertyName("seq_no_primary_term"); + writer.WriteBooleanValue(value.SeqNoPrimaryTerm.Value); + } + + if (value.StoredFields is not null) + { + writer.WritePropertyName("stored_fields"); + JsonSerializer.Serialize(writer, value.StoredFields, options); + } + + if (value.Pit is not null) + { + writer.WritePropertyName("pit"); + JsonSerializer.Serialize(writer, value.Pit, options); + } + + if (value.RuntimeMappings is not null) + { + writer.WritePropertyName("runtime_mappings"); + JsonSerializer.Serialize(writer, value.RuntimeMappings, options); + } + + if (value.Stats is not null) + { + writer.WritePropertyName("stats"); + JsonSerializer.Serialize(writer, value.Stats, options); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(SearchRequestConverter))] public partial class SearchRequest : PlainRequestBase { public SearchRequest() diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/Datafeed.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/Datafeed.g.cs index c7c3942e16d..90efe8af81a 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/Datafeed.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/Datafeed.g.cs @@ -24,70 +24,173 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Ml { + internal sealed class DatafeedConverter : JsonConverter + { + public override Datafeed Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + Dictionary? aggregations = default; + Elastic.Clients.Elasticsearch.Ml.DatafeedAuthorization? authorization = default; + Elastic.Clients.Elasticsearch.Ml.ChunkingConfig? chunkingConfig = default; + string datafeedId = default; + Elastic.Clients.Elasticsearch.Ml.DelayedDataCheckConfig delayedDataCheckConfig = default; + Elastic.Clients.Elasticsearch.Duration? frequency = default; + IReadOnlyCollection? indexes = default; + IReadOnlyCollection indices = default; + Elastic.Clients.Elasticsearch.IndicesOptions? indicesOptions = default; + string jobId = default; + int? maxEmptySearches = default; + Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer query = default; + Elastic.Clients.Elasticsearch.Duration? queryDelay = default; + Dictionary>? runtimeMappings = default; + Dictionary? scriptFields = default; + int? scrollSize = default; + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "aggregations") + { + aggregations = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "authorization") + { + authorization = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "chunking_config") + { + chunkingConfig = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "datafeed_id") + { + datafeedId = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "delayed_data_check_config") + { + delayedDataCheckConfig = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "frequency") + { + frequency = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "indexes") + { + indexes = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "indices") + { + indices = JsonSerializer.Deserialize>(ref reader, options); + continue; + } + + if (property == "indices_options") + { + indicesOptions = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "job_id") + { + jobId = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "max_empty_searches") + { + maxEmptySearches = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "query") + { + query = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "query_delay") + { + queryDelay = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "runtime_mappings") + { + runtimeMappings = JsonSerializer.Deserialize>?>(ref reader, options); + continue; + } + + if (property == "script_fields") + { + scriptFields = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "scroll_size") + { + scrollSize = JsonSerializer.Deserialize(ref reader, options); + continue; + } + } + } + + return new Datafeed { Aggregations = aggregations, Authorization = authorization, ChunkingConfig = chunkingConfig, DatafeedId = datafeedId, DelayedDataCheckConfig = delayedDataCheckConfig, Frequency = frequency, Indexes = indexes, Indices = indices, IndicesOptions = indicesOptions, JobId = jobId, MaxEmptySearches = maxEmptySearches, Query = query, QueryDelay = queryDelay, RuntimeMappings = runtimeMappings, ScriptFields = scriptFields, ScrollSize = scrollSize }; + } + + public override void Write(Utf8JsonWriter writer, Datafeed value, JsonSerializerOptions options) + { + throw new NotImplementedException("'Datafeed' is a readonly type, used only on responses and does not support being written to JSON."); + } + } + + [JsonConverter(typeof(DatafeedConverter))] public sealed partial class Datafeed { - [JsonInclude] - [JsonPropertyName("aggregations")] public Dictionary? Aggregations { get; init; } - [JsonInclude] - [JsonPropertyName("authorization")] public Elastic.Clients.Elasticsearch.Ml.DatafeedAuthorization? Authorization { get; init; } - [JsonInclude] - [JsonPropertyName("chunking_config")] public Elastic.Clients.Elasticsearch.Ml.ChunkingConfig? ChunkingConfig { get; init; } - [JsonInclude] - [JsonPropertyName("datafeed_id")] public string DatafeedId { get; init; } - [JsonInclude] - [JsonPropertyName("delayed_data_check_config")] public Elastic.Clients.Elasticsearch.Ml.DelayedDataCheckConfig DelayedDataCheckConfig { get; init; } - [JsonInclude] - [JsonPropertyName("frequency")] public Elastic.Clients.Elasticsearch.Duration? Frequency { get; init; } - [JsonInclude] - [JsonPropertyName("indexes")] public IReadOnlyCollection? Indexes { get; init; } - [JsonInclude] - [JsonPropertyName("indices")] public IReadOnlyCollection Indices { get; init; } - [JsonInclude] - [JsonPropertyName("indices_options")] public Elastic.Clients.Elasticsearch.IndicesOptions? IndicesOptions { get; init; } - [JsonInclude] - [JsonPropertyName("job_id")] public string JobId { get; init; } - [JsonInclude] - [JsonPropertyName("max_empty_searches")] public int? MaxEmptySearches { get; init; } - [JsonInclude] - [JsonPropertyName("query")] public Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer Query { get; init; } - [JsonInclude] - [JsonPropertyName("query_delay")] public Elastic.Clients.Elasticsearch.Duration? QueryDelay { get; init; } - [JsonInclude] - [JsonPropertyName("runtime_mappings")] public Dictionary>? RuntimeMappings { get; init; } - [JsonInclude] - [JsonPropertyName("script_fields")] public Dictionary? ScriptFields { get; init; } - [JsonInclude] - [JsonPropertyName("scroll_size")] public int? ScrollSize { get; init; } } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/DatafeedConfig.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/DatafeedConfig.g.cs index fbbbe26c4b8..b75a1e39ea1 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/DatafeedConfig.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/DatafeedConfig.g.cs @@ -24,66 +24,233 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Ml { + internal sealed class DatafeedConfigConverter : JsonConverter + { + public override DatafeedConfig Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new DatafeedConfig(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "aggregations" || property == "aggs") + { + variant.Aggregations = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "chunking_config") + { + variant.ChunkingConfig = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "datafeed_id") + { + variant.DatafeedId = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "delayed_data_check_config") + { + variant.DelayedDataCheckConfig = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "frequency") + { + variant.Frequency = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "indexes") + { + variant.Indexes = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "indices") + { + variant.Indices = JsonSerializer.Deserialize>(ref reader, options); + continue; + } + + if (property == "indices_options") + { + variant.IndicesOptions = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "job_id") + { + variant.JobId = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "max_empty_searches") + { + variant.MaxEmptySearches = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "query") + { + variant.Query = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "query_delay") + { + variant.QueryDelay = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "runtime_mappings") + { + variant.RuntimeMappings = JsonSerializer.Deserialize>?>(ref reader, options); + continue; + } + + if (property == "script_fields") + { + variant.ScriptFields = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "scroll_size") + { + variant.ScrollSize = JsonSerializer.Deserialize(ref reader, options); + continue; + } + } + } + + return variant; + } + + public override void Write(Utf8JsonWriter writer, DatafeedConfig value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Aggregations is not null) + { + writer.WritePropertyName("aggregations"); + JsonSerializer.Serialize(writer, value.Aggregations, options); + } + + if (value.ChunkingConfig is not null) + { + writer.WritePropertyName("chunking_config"); + JsonSerializer.Serialize(writer, value.ChunkingConfig, options); + } + + if (value.DatafeedId is not null) + { + writer.WritePropertyName("datafeed_id"); + JsonSerializer.Serialize(writer, value.DatafeedId, options); + } + + if (value.DelayedDataCheckConfig is not null) + { + writer.WritePropertyName("delayed_data_check_config"); + JsonSerializer.Serialize(writer, value.DelayedDataCheckConfig, options); + } + + if (value.Frequency is not null) + { + writer.WritePropertyName("frequency"); + JsonSerializer.Serialize(writer, value.Frequency, options); + } + + if (value.Indexes is not null) + { + writer.WritePropertyName("indexes"); + JsonSerializer.Serialize(writer, value.Indexes, options); + } + + writer.WritePropertyName("indices"); + JsonSerializer.Serialize(writer, value.Indices, options); + if (value.IndicesOptions is not null) + { + writer.WritePropertyName("indices_options"); + JsonSerializer.Serialize(writer, value.IndicesOptions, options); + } + + if (value.JobId is not null) + { + writer.WritePropertyName("job_id"); + JsonSerializer.Serialize(writer, value.JobId, options); + } + + if (value.MaxEmptySearches.HasValue) + { + writer.WritePropertyName("max_empty_searches"); + writer.WriteNumberValue(value.MaxEmptySearches.Value); + } + + writer.WritePropertyName("query"); + JsonSerializer.Serialize(writer, value.Query, options); + if (value.QueryDelay is not null) + { + writer.WritePropertyName("query_delay"); + JsonSerializer.Serialize(writer, value.QueryDelay, options); + } + + if (value.RuntimeMappings is not null) + { + writer.WritePropertyName("runtime_mappings"); + JsonSerializer.Serialize(writer, value.RuntimeMappings, options); + } + + if (value.ScriptFields is not null) + { + writer.WritePropertyName("script_fields"); + JsonSerializer.Serialize(writer, value.ScriptFields, options); + } + + if (value.ScrollSize.HasValue) + { + writer.WritePropertyName("scroll_size"); + writer.WriteNumberValue(value.ScrollSize.Value); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(DatafeedConfigConverter))] public sealed partial class DatafeedConfig { - [JsonInclude] - [JsonPropertyName("aggregations")] public Dictionary? Aggregations { get; set; } - [JsonInclude] - [JsonPropertyName("chunking_config")] public Elastic.Clients.Elasticsearch.Ml.ChunkingConfig? ChunkingConfig { get; set; } - [JsonInclude] - [JsonPropertyName("datafeed_id")] public Elastic.Clients.Elasticsearch.Id? DatafeedId { get; set; } - [JsonInclude] - [JsonPropertyName("delayed_data_check_config")] public Elastic.Clients.Elasticsearch.Ml.DelayedDataCheckConfig? DelayedDataCheckConfig { get; set; } - [JsonInclude] - [JsonPropertyName("frequency")] public Elastic.Clients.Elasticsearch.Duration? Frequency { get; set; } - [JsonInclude] - [JsonPropertyName("indexes")] public IEnumerable? Indexes { get; set; } - [JsonInclude] - [JsonPropertyName("indices")] public IEnumerable Indices { get; set; } - [JsonInclude] - [JsonPropertyName("indices_options")] public Elastic.Clients.Elasticsearch.IndicesOptions? IndicesOptions { get; set; } - [JsonInclude] - [JsonPropertyName("job_id")] public Elastic.Clients.Elasticsearch.Id? JobId { get; set; } - [JsonInclude] - [JsonPropertyName("max_empty_searches")] public int? MaxEmptySearches { get; set; } - [JsonInclude] - [JsonPropertyName("query")] public Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer Query { get; set; } - [JsonInclude] - [JsonPropertyName("query_delay")] public Elastic.Clients.Elasticsearch.Duration? QueryDelay { get; set; } - [JsonInclude] - [JsonPropertyName("runtime_mappings")] public Dictionary>? RuntimeMappings { get; set; } - [JsonInclude] - [JsonPropertyName("script_fields")] public Dictionary? ScriptFields { get; set; } - [JsonInclude] - [JsonPropertyName("scroll_size")] public int? ScrollSize { get; set; } } diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/DataframeAnalysisClassification.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/DataframeAnalysisClassification.g.cs index 4a70a1acef8..1d790843279 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/DataframeAnalysisClassification.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/DataframeAnalysisClassification.g.cs @@ -24,86 +24,307 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Ml { + internal sealed class DataframeAnalysisClassificationConverter : JsonConverter + { + public override DataframeAnalysisClassification Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new DataframeAnalysisClassification(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "alpha") + { + variant.Alpha = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "class_assignment_objective") + { + variant.ClassAssignmentObjective = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "dependent_variable") + { + variant.DependentVariable = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "downsample_factor") + { + variant.DownsampleFactor = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "early_stopping_enabled") + { + variant.EarlyStoppingEnabled = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "eta") + { + variant.Eta = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "eta_growth_rate_per_tree") + { + variant.EtaGrowthRatePerTree = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "feature_bag_fraction") + { + variant.FeatureBagFraction = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "feature_processors") + { + variant.FeatureProcessors = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "gamma") + { + variant.Gamma = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "lambda") + { + variant.Lambda = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "max_optimization_rounds_per_hyperparameter") + { + variant.MaxOptimizationRoundsPerHyperparameter = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "max_trees" || property == "maximum_number_trees") + { + variant.MaxTrees = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "num_top_classes") + { + variant.NumTopClasses = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "num_top_feature_importance_values") + { + variant.NumTopFeatureImportanceValues = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "prediction_field_name") + { + variant.PredictionFieldName = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "randomize_seed") + { + variant.RandomizeSeed = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "soft_tree_depth_limit") + { + variant.SoftTreeDepthLimit = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "soft_tree_depth_tolerance") + { + variant.SoftTreeDepthTolerance = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "training_percent") + { + variant.TrainingPercent = JsonSerializer.Deserialize(ref reader, options); + continue; + } + } + } + + return variant; + } + + public override void Write(Utf8JsonWriter writer, DataframeAnalysisClassification value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Alpha.HasValue) + { + writer.WritePropertyName("alpha"); + writer.WriteNumberValue(value.Alpha.Value); + } + + if (!string.IsNullOrEmpty(value.ClassAssignmentObjective)) + { + writer.WritePropertyName("class_assignment_objective"); + writer.WriteStringValue(value.ClassAssignmentObjective); + } + + writer.WritePropertyName("dependent_variable"); + writer.WriteStringValue(value.DependentVariable); + if (value.DownsampleFactor.HasValue) + { + writer.WritePropertyName("downsample_factor"); + writer.WriteNumberValue(value.DownsampleFactor.Value); + } + + if (value.EarlyStoppingEnabled.HasValue) + { + writer.WritePropertyName("early_stopping_enabled"); + writer.WriteBooleanValue(value.EarlyStoppingEnabled.Value); + } + + if (value.Eta.HasValue) + { + writer.WritePropertyName("eta"); + writer.WriteNumberValue(value.Eta.Value); + } + + if (value.EtaGrowthRatePerTree.HasValue) + { + writer.WritePropertyName("eta_growth_rate_per_tree"); + writer.WriteNumberValue(value.EtaGrowthRatePerTree.Value); + } + + if (value.FeatureBagFraction.HasValue) + { + writer.WritePropertyName("feature_bag_fraction"); + writer.WriteNumberValue(value.FeatureBagFraction.Value); + } + + if (value.FeatureProcessors is not null) + { + writer.WritePropertyName("feature_processors"); + JsonSerializer.Serialize(writer, value.FeatureProcessors, options); + } + + if (value.Gamma.HasValue) + { + writer.WritePropertyName("gamma"); + writer.WriteNumberValue(value.Gamma.Value); + } + + if (value.Lambda.HasValue) + { + writer.WritePropertyName("lambda"); + writer.WriteNumberValue(value.Lambda.Value); + } + + if (value.MaxOptimizationRoundsPerHyperparameter.HasValue) + { + writer.WritePropertyName("max_optimization_rounds_per_hyperparameter"); + writer.WriteNumberValue(value.MaxOptimizationRoundsPerHyperparameter.Value); + } + + if (value.MaxTrees.HasValue) + { + writer.WritePropertyName("max_trees"); + writer.WriteNumberValue(value.MaxTrees.Value); + } + + if (value.NumTopClasses.HasValue) + { + writer.WritePropertyName("num_top_classes"); + writer.WriteNumberValue(value.NumTopClasses.Value); + } + + if (value.NumTopFeatureImportanceValues.HasValue) + { + writer.WritePropertyName("num_top_feature_importance_values"); + writer.WriteNumberValue(value.NumTopFeatureImportanceValues.Value); + } + + if (value.PredictionFieldName is not null) + { + writer.WritePropertyName("prediction_field_name"); + JsonSerializer.Serialize(writer, value.PredictionFieldName, options); + } + + if (value.RandomizeSeed.HasValue) + { + writer.WritePropertyName("randomize_seed"); + writer.WriteNumberValue(value.RandomizeSeed.Value); + } + + if (value.SoftTreeDepthLimit.HasValue) + { + writer.WritePropertyName("soft_tree_depth_limit"); + writer.WriteNumberValue(value.SoftTreeDepthLimit.Value); + } + + if (value.SoftTreeDepthTolerance.HasValue) + { + writer.WritePropertyName("soft_tree_depth_tolerance"); + writer.WriteNumberValue(value.SoftTreeDepthTolerance.Value); + } + + if (value.TrainingPercent is not null) + { + writer.WritePropertyName("training_percent"); + JsonSerializer.Serialize(writer, value.TrainingPercent, options); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(DataframeAnalysisClassificationConverter))] public sealed partial class DataframeAnalysisClassification : IDataframeAnalysisVariant { - [JsonInclude] - [JsonPropertyName("alpha")] public double? Alpha { get; set; } - [JsonInclude] - [JsonPropertyName("class_assignment_objective")] public string? ClassAssignmentObjective { get; set; } - [JsonInclude] - [JsonPropertyName("dependent_variable")] public string DependentVariable { get; set; } - [JsonInclude] - [JsonPropertyName("downsample_factor")] public double? DownsampleFactor { get; set; } - [JsonInclude] - [JsonPropertyName("early_stopping_enabled")] public bool? EarlyStoppingEnabled { get; set; } - [JsonInclude] - [JsonPropertyName("eta")] public double? Eta { get; set; } - [JsonInclude] - [JsonPropertyName("eta_growth_rate_per_tree")] public double? EtaGrowthRatePerTree { get; set; } - [JsonInclude] - [JsonPropertyName("feature_bag_fraction")] public double? FeatureBagFraction { get; set; } - [JsonInclude] - [JsonPropertyName("feature_processors")] public IEnumerable? FeatureProcessors { get; set; } - [JsonInclude] - [JsonPropertyName("gamma")] public double? Gamma { get; set; } - [JsonInclude] - [JsonPropertyName("lambda")] public double? Lambda { get; set; } - [JsonInclude] - [JsonPropertyName("max_optimization_rounds_per_hyperparameter")] public int? MaxOptimizationRoundsPerHyperparameter { get; set; } - [JsonInclude] - [JsonPropertyName("max_trees")] public int? MaxTrees { get; set; } - [JsonInclude] - [JsonPropertyName("num_top_classes")] public int? NumTopClasses { get; set; } - [JsonInclude] - [JsonPropertyName("num_top_feature_importance_values")] public int? NumTopFeatureImportanceValues { get; set; } - [JsonInclude] - [JsonPropertyName("prediction_field_name")] public Elastic.Clients.Elasticsearch.Field? PredictionFieldName { get; set; } - [JsonInclude] - [JsonPropertyName("randomize_seed")] public double? RandomizeSeed { get; set; } - [JsonInclude] - [JsonPropertyName("soft_tree_depth_limit")] public int? SoftTreeDepthLimit { get; set; } - [JsonInclude] - [JsonPropertyName("soft_tree_depth_tolerance")] public double? SoftTreeDepthTolerance { get; set; } - [JsonInclude] - [JsonPropertyName("training_percent")] public Elastic.Clients.Elasticsearch.Percentage? TrainingPercent { get; set; } } diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/DataframeAnalysisRegression.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/DataframeAnalysisRegression.g.cs index 4e50b33252b..81ba955d731 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/DataframeAnalysisRegression.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Ml/DataframeAnalysisRegression.g.cs @@ -24,86 +24,307 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Ml { + internal sealed class DataframeAnalysisRegressionConverter : JsonConverter + { + public override DataframeAnalysisRegression Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new DataframeAnalysisRegression(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "alpha") + { + variant.Alpha = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "dependent_variable") + { + variant.DependentVariable = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "downsample_factor") + { + variant.DownsampleFactor = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "early_stopping_enabled") + { + variant.EarlyStoppingEnabled = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "eta") + { + variant.Eta = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "eta_growth_rate_per_tree") + { + variant.EtaGrowthRatePerTree = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "feature_bag_fraction") + { + variant.FeatureBagFraction = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "feature_processors") + { + variant.FeatureProcessors = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "gamma") + { + variant.Gamma = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "lambda") + { + variant.Lambda = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "loss_function") + { + variant.LossFunction = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "loss_function_parameter") + { + variant.LossFunctionParameter = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "max_optimization_rounds_per_hyperparameter") + { + variant.MaxOptimizationRoundsPerHyperparameter = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "max_trees" || property == "maximum_number_trees") + { + variant.MaxTrees = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "num_top_feature_importance_values") + { + variant.NumTopFeatureImportanceValues = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "prediction_field_name") + { + variant.PredictionFieldName = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "randomize_seed") + { + variant.RandomizeSeed = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "soft_tree_depth_limit") + { + variant.SoftTreeDepthLimit = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "soft_tree_depth_tolerance") + { + variant.SoftTreeDepthTolerance = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "training_percent") + { + variant.TrainingPercent = JsonSerializer.Deserialize(ref reader, options); + continue; + } + } + } + + return variant; + } + + public override void Write(Utf8JsonWriter writer, DataframeAnalysisRegression value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Alpha.HasValue) + { + writer.WritePropertyName("alpha"); + writer.WriteNumberValue(value.Alpha.Value); + } + + writer.WritePropertyName("dependent_variable"); + writer.WriteStringValue(value.DependentVariable); + if (value.DownsampleFactor.HasValue) + { + writer.WritePropertyName("downsample_factor"); + writer.WriteNumberValue(value.DownsampleFactor.Value); + } + + if (value.EarlyStoppingEnabled.HasValue) + { + writer.WritePropertyName("early_stopping_enabled"); + writer.WriteBooleanValue(value.EarlyStoppingEnabled.Value); + } + + if (value.Eta.HasValue) + { + writer.WritePropertyName("eta"); + writer.WriteNumberValue(value.Eta.Value); + } + + if (value.EtaGrowthRatePerTree.HasValue) + { + writer.WritePropertyName("eta_growth_rate_per_tree"); + writer.WriteNumberValue(value.EtaGrowthRatePerTree.Value); + } + + if (value.FeatureBagFraction.HasValue) + { + writer.WritePropertyName("feature_bag_fraction"); + writer.WriteNumberValue(value.FeatureBagFraction.Value); + } + + if (value.FeatureProcessors is not null) + { + writer.WritePropertyName("feature_processors"); + JsonSerializer.Serialize(writer, value.FeatureProcessors, options); + } + + if (value.Gamma.HasValue) + { + writer.WritePropertyName("gamma"); + writer.WriteNumberValue(value.Gamma.Value); + } + + if (value.Lambda.HasValue) + { + writer.WritePropertyName("lambda"); + writer.WriteNumberValue(value.Lambda.Value); + } + + if (!string.IsNullOrEmpty(value.LossFunction)) + { + writer.WritePropertyName("loss_function"); + writer.WriteStringValue(value.LossFunction); + } + + if (value.LossFunctionParameter.HasValue) + { + writer.WritePropertyName("loss_function_parameter"); + writer.WriteNumberValue(value.LossFunctionParameter.Value); + } + + if (value.MaxOptimizationRoundsPerHyperparameter.HasValue) + { + writer.WritePropertyName("max_optimization_rounds_per_hyperparameter"); + writer.WriteNumberValue(value.MaxOptimizationRoundsPerHyperparameter.Value); + } + + if (value.MaxTrees.HasValue) + { + writer.WritePropertyName("max_trees"); + writer.WriteNumberValue(value.MaxTrees.Value); + } + + if (value.NumTopFeatureImportanceValues.HasValue) + { + writer.WritePropertyName("num_top_feature_importance_values"); + writer.WriteNumberValue(value.NumTopFeatureImportanceValues.Value); + } + + if (value.PredictionFieldName is not null) + { + writer.WritePropertyName("prediction_field_name"); + JsonSerializer.Serialize(writer, value.PredictionFieldName, options); + } + + if (value.RandomizeSeed.HasValue) + { + writer.WritePropertyName("randomize_seed"); + writer.WriteNumberValue(value.RandomizeSeed.Value); + } + + if (value.SoftTreeDepthLimit.HasValue) + { + writer.WritePropertyName("soft_tree_depth_limit"); + writer.WriteNumberValue(value.SoftTreeDepthLimit.Value); + } + + if (value.SoftTreeDepthTolerance.HasValue) + { + writer.WritePropertyName("soft_tree_depth_tolerance"); + writer.WriteNumberValue(value.SoftTreeDepthTolerance.Value); + } + + if (value.TrainingPercent is not null) + { + writer.WritePropertyName("training_percent"); + JsonSerializer.Serialize(writer, value.TrainingPercent, options); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(DataframeAnalysisRegressionConverter))] public sealed partial class DataframeAnalysisRegression : IDataframeAnalysisVariant { - [JsonInclude] - [JsonPropertyName("alpha")] public double? Alpha { get; set; } - [JsonInclude] - [JsonPropertyName("dependent_variable")] public string DependentVariable { get; set; } - [JsonInclude] - [JsonPropertyName("downsample_factor")] public double? DownsampleFactor { get; set; } - [JsonInclude] - [JsonPropertyName("early_stopping_enabled")] public bool? EarlyStoppingEnabled { get; set; } - [JsonInclude] - [JsonPropertyName("eta")] public double? Eta { get; set; } - [JsonInclude] - [JsonPropertyName("eta_growth_rate_per_tree")] public double? EtaGrowthRatePerTree { get; set; } - [JsonInclude] - [JsonPropertyName("feature_bag_fraction")] public double? FeatureBagFraction { get; set; } - [JsonInclude] - [JsonPropertyName("feature_processors")] public IEnumerable? FeatureProcessors { get; set; } - [JsonInclude] - [JsonPropertyName("gamma")] public double? Gamma { get; set; } - [JsonInclude] - [JsonPropertyName("lambda")] public double? Lambda { get; set; } - [JsonInclude] - [JsonPropertyName("loss_function")] public string? LossFunction { get; set; } - [JsonInclude] - [JsonPropertyName("loss_function_parameter")] public double? LossFunctionParameter { get; set; } - [JsonInclude] - [JsonPropertyName("max_optimization_rounds_per_hyperparameter")] public int? MaxOptimizationRoundsPerHyperparameter { get; set; } - [JsonInclude] - [JsonPropertyName("max_trees")] public int? MaxTrees { get; set; } - [JsonInclude] - [JsonPropertyName("num_top_feature_importance_values")] public int? NumTopFeatureImportanceValues { get; set; } - [JsonInclude] - [JsonPropertyName("prediction_field_name")] public Elastic.Clients.Elasticsearch.Field? PredictionFieldName { get; set; } - [JsonInclude] - [JsonPropertyName("randomize_seed")] public double? RandomizeSeed { get; set; } - [JsonInclude] - [JsonPropertyName("soft_tree_depth_limit")] public int? SoftTreeDepthLimit { get; set; } - [JsonInclude] - [JsonPropertyName("soft_tree_depth_tolerance")] public double? SoftTreeDepthTolerance { get; set; } - [JsonInclude] - [JsonPropertyName("training_percent")] public Elastic.Clients.Elasticsearch.Percentage? TrainingPercent { get; set; } } diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/MultisearchBody.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/MultisearchBody.g.cs index e2d77a45b4b..d2208eea5fe 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/MultisearchBody.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/MultisearchBody.g.cs @@ -24,123 +24,438 @@ #nullable restore namespace Elastic.Clients.Elasticsearch { + internal sealed class MultisearchBodyConverter : JsonConverter + { + public override MultisearchBody Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new MultisearchBody(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "_source") + { + variant.Source = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "aggregations" || property == "aggs") + { + variant.Aggregations = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "collapse") + { + variant.Collapse = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "docvalue_fields") + { + variant.DocvalueFields = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "explain") + { + variant.Explain = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "fields") + { + variant.Fields = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "from") + { + variant.From = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "highlight") + { + variant.Highlight = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "indices_boost") + { + variant.IndicesBoost = JsonSerializer.Deserialize>?>(ref reader, options); + continue; + } + + if (property == "min_score") + { + variant.MinScore = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "pit") + { + variant.Pit = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "post_filter") + { + variant.PostFilter = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "profile") + { + variant.Profile = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "query") + { + variant.Query = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "rescore") + { + variant.Rescore = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "runtime_mappings") + { + variant.RuntimeMappings = JsonSerializer.Deserialize>?>(ref reader, options); + continue; + } + + if (property == "script_fields") + { + variant.ScriptFields = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "search_after") + { + variant.SearchAfter = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "seq_no_primary_term") + { + variant.SeqNoPrimaryTerm = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "size") + { + variant.Size = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "sort") + { + variant.Sort = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "stats") + { + variant.Stats = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "stored_fields") + { + variant.StoredFields = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "suggest") + { + variant.Suggest = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "terminate_after") + { + variant.TerminateAfter = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "timeout") + { + variant.Timeout = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "track_scores") + { + variant.TrackScores = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "track_total_hits") + { + variant.TrackTotalHits = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "version") + { + variant.Version = JsonSerializer.Deserialize(ref reader, options); + continue; + } + } + } + + return variant; + } + + public override void Write(Utf8JsonWriter writer, MultisearchBody value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Source is not null) + { + writer.WritePropertyName("_source"); + JsonSerializer.Serialize(writer, value.Source, options); + } + + if (value.Aggregations is not null) + { + writer.WritePropertyName("aggregations"); + JsonSerializer.Serialize(writer, value.Aggregations, options); + } + + if (value.Collapse is not null) + { + writer.WritePropertyName("collapse"); + JsonSerializer.Serialize(writer, value.Collapse, options); + } + + if (value.DocvalueFields is not null) + { + writer.WritePropertyName("docvalue_fields"); + JsonSerializer.Serialize(writer, value.DocvalueFields, options); + } + + if (value.Explain.HasValue) + { + writer.WritePropertyName("explain"); + writer.WriteBooleanValue(value.Explain.Value); + } + + if (value.Fields is not null) + { + writer.WritePropertyName("fields"); + JsonSerializer.Serialize(writer, value.Fields, options); + } + + if (value.From.HasValue) + { + writer.WritePropertyName("from"); + writer.WriteNumberValue(value.From.Value); + } + + if (value.Highlight is not null) + { + writer.WritePropertyName("highlight"); + JsonSerializer.Serialize(writer, value.Highlight, options); + } + + if (value.IndicesBoost is not null) + { + writer.WritePropertyName("indices_boost"); + JsonSerializer.Serialize(writer, value.IndicesBoost, options); + } + + if (value.MinScore.HasValue) + { + writer.WritePropertyName("min_score"); + writer.WriteNumberValue(value.MinScore.Value); + } + + if (value.Pit is not null) + { + writer.WritePropertyName("pit"); + JsonSerializer.Serialize(writer, value.Pit, options); + } + + if (value.PostFilter is not null) + { + writer.WritePropertyName("post_filter"); + JsonSerializer.Serialize(writer, value.PostFilter, options); + } + + if (value.Profile.HasValue) + { + writer.WritePropertyName("profile"); + writer.WriteBooleanValue(value.Profile.Value); + } + + if (value.Query is not null) + { + writer.WritePropertyName("query"); + JsonSerializer.Serialize(writer, value.Query, options); + } + + if (value.Rescore is not null) + { + writer.WritePropertyName("rescore"); + JsonSerializer.Serialize(writer, value.Rescore, options); + } + + if (value.RuntimeMappings is not null) + { + writer.WritePropertyName("runtime_mappings"); + JsonSerializer.Serialize(writer, value.RuntimeMappings, options); + } + + if (value.ScriptFields is not null) + { + writer.WritePropertyName("script_fields"); + JsonSerializer.Serialize(writer, value.ScriptFields, options); + } + + if (value.SearchAfter is not null) + { + writer.WritePropertyName("search_after"); + JsonSerializer.Serialize(writer, value.SearchAfter, options); + } + + if (value.SeqNoPrimaryTerm.HasValue) + { + writer.WritePropertyName("seq_no_primary_term"); + writer.WriteBooleanValue(value.SeqNoPrimaryTerm.Value); + } + + if (value.Size.HasValue) + { + writer.WritePropertyName("size"); + writer.WriteNumberValue(value.Size.Value); + } + + if (value.Sort is not null) + { + writer.WritePropertyName("sort"); + JsonSerializer.Serialize(writer, value.Sort, options); + } + + if (value.Stats is not null) + { + writer.WritePropertyName("stats"); + JsonSerializer.Serialize(writer, value.Stats, options); + } + + if (value.StoredFields is not null) + { + writer.WritePropertyName("stored_fields"); + JsonSerializer.Serialize(writer, value.StoredFields, options); + } + + if (value.Suggest is not null) + { + writer.WritePropertyName("suggest"); + JsonSerializer.Serialize(writer, value.Suggest, options); + } + + if (value.TerminateAfter.HasValue) + { + writer.WritePropertyName("terminate_after"); + writer.WriteNumberValue(value.TerminateAfter.Value); + } + + if (!string.IsNullOrEmpty(value.Timeout)) + { + writer.WritePropertyName("timeout"); + writer.WriteStringValue(value.Timeout); + } + + if (value.TrackScores.HasValue) + { + writer.WritePropertyName("track_scores"); + writer.WriteBooleanValue(value.TrackScores.Value); + } + + if (value.TrackTotalHits is not null) + { + writer.WritePropertyName("track_total_hits"); + JsonSerializer.Serialize(writer, value.TrackTotalHits, options); + } + + if (value.Version.HasValue) + { + writer.WritePropertyName("version"); + writer.WriteBooleanValue(value.Version.Value); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(MultisearchBodyConverter))] public sealed partial class MultisearchBody { - [JsonInclude] - [JsonPropertyName("_source")] public Elastic.Clients.Elasticsearch.SourceConfig? Source { get; set; } - [JsonInclude] - [JsonPropertyName("aggregations")] public Dictionary? Aggregations { get; set; } - [JsonInclude] - [JsonPropertyName("collapse")] public Elastic.Clients.Elasticsearch.FieldCollapse? Collapse { get; set; } - [JsonInclude] - [JsonPropertyName("docvalue_fields")] public IEnumerable? DocvalueFields { get; set; } - [JsonInclude] - [JsonPropertyName("explain")] public bool? Explain { get; set; } - [JsonInclude] - [JsonPropertyName("fields")] public IEnumerable? Fields { get; set; } - [JsonInclude] - [JsonPropertyName("from")] public int? From { get; set; } - [JsonInclude] - [JsonPropertyName("highlight")] public Elastic.Clients.Elasticsearch.Highlight? Highlight { get; set; } - [JsonInclude] - [JsonPropertyName("indices_boost")] public IEnumerable>? IndicesBoost { get; set; } - [JsonInclude] - [JsonPropertyName("min_score")] public double? MinScore { get; set; } - [JsonInclude] - [JsonPropertyName("pit")] public Elastic.Clients.Elasticsearch.PointInTimeReference? Pit { get; set; } - [JsonInclude] - [JsonPropertyName("post_filter")] public Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? PostFilter { get; set; } - [JsonInclude] - [JsonPropertyName("profile")] public bool? Profile { get; set; } - [JsonInclude] - [JsonPropertyName("query")] public Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? Query { get; set; } - [JsonInclude] - [JsonPropertyName("rescore")] public IEnumerable? Rescore { get; set; } - [JsonInclude] - [JsonPropertyName("runtime_mappings")] public Dictionary>? RuntimeMappings { get; set; } - [JsonInclude] - [JsonPropertyName("script_fields")] public Dictionary? ScriptFields { get; set; } - [JsonInclude] - [JsonPropertyName("search_after")] public IEnumerable? SearchAfter { get; set; } - [JsonInclude] - [JsonPropertyName("seq_no_primary_term")] public bool? SeqNoPrimaryTerm { get; set; } - [JsonInclude] - [JsonPropertyName("size")] public int? Size { get; set; } - [JsonInclude] - [JsonPropertyName("sort")] [JsonConverter(typeof(SortConverter))] public IEnumerable? Sort { get; set; } - [JsonInclude] - [JsonPropertyName("stats")] public IEnumerable? Stats { get; set; } - [JsonInclude] - [JsonPropertyName("stored_fields")] public Elastic.Clients.Elasticsearch.Fields? StoredFields { get; set; } - [JsonInclude] - [JsonPropertyName("suggest")] public Elastic.Clients.Elasticsearch.Suggester? Suggest { get; set; } - [JsonInclude] - [JsonPropertyName("terminate_after")] public long? TerminateAfter { get; set; } - [JsonInclude] - [JsonPropertyName("timeout")] public string? Timeout { get; set; } - [JsonInclude] - [JsonPropertyName("track_scores")] public bool? TrackScores { get; set; } - [JsonInclude] - [JsonPropertyName("track_total_hits")] public Elastic.Clients.Elasticsearch.TrackHits? TrackTotalHits { get; set; } - [JsonInclude] - [JsonPropertyName("version")] public bool? Version { get; set; } } diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Slm/Statistics.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Slm/Statistics.g.cs index 6aff197c093..2dcab132e96 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Slm/Statistics.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Slm/Statistics.g.cs @@ -24,46 +24,119 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Slm { + internal sealed class StatisticsConverter : JsonConverter + { + public override Statistics Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + string? policy = default; + Elastic.Clients.Elasticsearch.Duration? retentionDeletionTime = default; + long? retentionDeletionTimeMillis = default; + long? retentionFailed = default; + long? retentionRuns = default; + long? retentionTimedOut = default; + long? totalSnapshotDeletionFailures = default; + long? totalSnapshotsDeleted = default; + long? totalSnapshotsFailed = default; + long? totalSnapshotsTaken = default; + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "policy") + { + policy = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "retention_deletion_time") + { + retentionDeletionTime = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "retention_deletion_time_millis") + { + retentionDeletionTimeMillis = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "retention_failed") + { + retentionFailed = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "retention_runs") + { + retentionRuns = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "retention_timed_out") + { + retentionTimedOut = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "total_snapshot_deletion_failures") + { + totalSnapshotDeletionFailures = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "total_snapshots_deleted") + { + totalSnapshotsDeleted = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "total_snapshots_failed") + { + totalSnapshotsFailed = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "total_snapshots_taken") + { + totalSnapshotsTaken = JsonSerializer.Deserialize(ref reader, options); + continue; + } + } + } + + return new Statistics { Policy = policy, RetentionDeletionTime = retentionDeletionTime, RetentionDeletionTimeMillis = retentionDeletionTimeMillis, RetentionFailed = retentionFailed, RetentionRuns = retentionRuns, RetentionTimedOut = retentionTimedOut, TotalSnapshotDeletionFailures = totalSnapshotDeletionFailures, TotalSnapshotsDeleted = totalSnapshotsDeleted, TotalSnapshotsFailed = totalSnapshotsFailed, TotalSnapshotsTaken = totalSnapshotsTaken }; + } + + public override void Write(Utf8JsonWriter writer, Statistics value, JsonSerializerOptions options) + { + throw new NotImplementedException("'Statistics' is a readonly type, used only on responses and does not support being written to JSON."); + } + } + + [JsonConverter(typeof(StatisticsConverter))] public sealed partial class Statistics { - [JsonInclude] - [JsonPropertyName("policy")] public string? Policy { get; init; } - [JsonInclude] - [JsonPropertyName("retention_deletion_time")] public Elastic.Clients.Elasticsearch.Duration? RetentionDeletionTime { get; init; } - [JsonInclude] - [JsonPropertyName("retention_deletion_time_millis")] public long? RetentionDeletionTimeMillis { get; init; } - [JsonInclude] - [JsonPropertyName("retention_failed")] public long? RetentionFailed { get; init; } - [JsonInclude] - [JsonPropertyName("retention_runs")] public long? RetentionRuns { get; init; } - [JsonInclude] - [JsonPropertyName("retention_timed_out")] public long? RetentionTimedOut { get; init; } - [JsonInclude] - [JsonPropertyName("total_snapshot_deletion_failures")] public long? TotalSnapshotDeletionFailures { get; init; } - [JsonInclude] - [JsonPropertyName("total_snapshots_deleted")] public long? TotalSnapshotsDeleted { get; init; } - [JsonInclude] - [JsonPropertyName("total_snapshots_failed")] public long? TotalSnapshotsFailed { get; init; } - [JsonInclude] - [JsonPropertyName("total_snapshots_taken")] public long? TotalSnapshotsTaken { get; init; } } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Snapshot/RepositorySettings.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Snapshot/RepositorySettings.g.cs index 6dcba8bddf9..e506e574868 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Snapshot/RepositorySettings.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Snapshot/RepositorySettings.g.cs @@ -24,26 +24,97 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.Snapshot { + internal sealed class RepositorySettingsConverter : JsonConverter + { + public override RepositorySettings Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new RepositorySettings(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "chunk_size") + { + variant.ChunkSize = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "compress") + { + variant.Compress = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "concurrent_streams") + { + variant.ConcurrentStreams = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "location") + { + variant.Location = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "read_only" || property == "readonly") + { + variant.ReadOnly = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + } + } + + return variant; + } + + public override void Write(Utf8JsonWriter writer, RepositorySettings value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (!string.IsNullOrEmpty(value.ChunkSize)) + { + writer.WritePropertyName("chunk_size"); + writer.WriteStringValue(value.ChunkSize); + } + + if (value.Compress is not null) + { + writer.WritePropertyName("compress"); + JsonSerializer.Serialize(writer, value.Compress, options); + } + + if (value.ConcurrentStreams is not null) + { + writer.WritePropertyName("concurrent_streams"); + JsonSerializer.Serialize(writer, value.ConcurrentStreams, options); + } + + writer.WritePropertyName("location"); + writer.WriteStringValue(value.Location); + if (value.ReadOnly is not null) + { + writer.WritePropertyName("read_only"); + JsonSerializer.Serialize(writer, value.ReadOnly, options); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(RepositorySettingsConverter))] public sealed partial class RepositorySettings { - [JsonInclude] - [JsonPropertyName("chunk_size")] public string? ChunkSize { get; set; } - [JsonInclude] - [JsonPropertyName("compress")] public Union? Compress { get; set; } - [JsonInclude] - [JsonPropertyName("concurrent_streams")] public Union? ConcurrentStreams { get; set; } - [JsonInclude] - [JsonPropertyName("location")] public string Location { get; set; } - [JsonInclude] - [JsonPropertyName("read_only")] public Union? ReadOnly { get; set; } } diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/SourceFilter.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/SourceFilter.g.cs index e4d52e1473b..01ae4133220 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/SourceFilter.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/SourceFilter.g.cs @@ -24,14 +24,59 @@ #nullable restore namespace Elastic.Clients.Elasticsearch { + internal sealed class SourceFilterConverter : JsonConverter + { + public override SourceFilter Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new SourceFilter(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "excludes" || property == "exclude") + { + variant.Excludes = JsonSerializer.Deserialize(ref reader, options); + continue; + } + + if (property == "includes" || property == "include") + { + variant.Includes = JsonSerializer.Deserialize(ref reader, options); + continue; + } + } + } + + return variant; + } + + public override void Write(Utf8JsonWriter writer, SourceFilter value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Excludes is not null) + { + writer.WritePropertyName("excludes"); + JsonSerializer.Serialize(writer, value.Excludes, options); + } + + if (value.Includes is not null) + { + writer.WritePropertyName("includes"); + JsonSerializer.Serialize(writer, value.Includes, options); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(SourceFilterConverter))] public sealed partial class SourceFilter { - [JsonInclude] - [JsonPropertyName("excludes")] public Elastic.Clients.Elasticsearch.Fields? Excludes { get; set; } - [JsonInclude] - [JsonPropertyName("includes")] public Elastic.Clients.Elasticsearch.Fields? Includes { get; set; } } diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/TransformManagement/Pivot.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/TransformManagement/Pivot.g.cs index c18face2864..62cee06a21d 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/TransformManagement/Pivot.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/TransformManagement/Pivot.g.cs @@ -24,14 +24,59 @@ #nullable restore namespace Elastic.Clients.Elasticsearch.TransformManagement { + internal sealed class PivotConverter : JsonConverter + { + public override Pivot Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException("Unexpected JSON detected."); + var variant = new Pivot(); + while (reader.Read() && reader.TokenType != JsonTokenType.EndObject) + { + if (reader.TokenType == JsonTokenType.PropertyName) + { + var property = reader.GetString(); + if (property == "aggregations" || property == "aggs") + { + variant.Aggregations = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + + if (property == "group_by") + { + variant.GroupBy = JsonSerializer.Deserialize?>(ref reader, options); + continue; + } + } + } + + return variant; + } + + public override void Write(Utf8JsonWriter writer, Pivot value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + if (value.Aggregations is not null) + { + writer.WritePropertyName("aggregations"); + JsonSerializer.Serialize(writer, value.Aggregations, options); + } + + if (value.GroupBy is not null) + { + writer.WritePropertyName("group_by"); + JsonSerializer.Serialize(writer, value.GroupBy, options); + } + + writer.WriteEndObject(); + } + } + + [JsonConverter(typeof(PivotConverter))] public sealed partial class Pivot { - [JsonInclude] - [JsonPropertyName("aggregations")] public Dictionary? Aggregations { get; set; } - [JsonInclude] - [JsonPropertyName("group_by")] public Dictionary? GroupBy { get; set; } } diff --git a/tests/Tests/Serialization/Mapping/PropertiesSerializationTests.cs b/tests/Tests/Serialization/Mapping/PropertiesSerializationTests.cs index c6c7d435a84..8b8fad40edd 100644 --- a/tests/Tests/Serialization/Mapping/PropertiesSerializationTests.cs +++ b/tests/Tests/Serialization/Mapping/PropertiesSerializationTests.cs @@ -15,7 +15,7 @@ public class PropertiesSerializationTests : SerializerTestBase [U] public async Task CanSerialize_Properties_WithPropertyNameExpression() { - var result = await RoundTripAndVerifyJson(new Properties + var result = await RoundTripAndVerifyJsonAsync(new Properties { { p => p.Name, new TextProperty { Boost = 1.2 } } }); @@ -27,7 +27,7 @@ public async Task CanSerialize_Properties_WithPropertyNameExpression() [U] public async Task CanSerialize_MultipleProperties_WithPropertyNameExpression() { - var result = await RoundTripAndVerifyJson(new Properties + var result = await RoundTripAndVerifyJsonAsync(new Properties { { p => p.Name, new TextProperty { Boost = 1.2 } }, { p => p.Description, new TextProperty { Boost = 1.4 } } diff --git a/tests/Tests/Serialization/SearchRequestWithAggsSerializationTests.cs b/tests/Tests/Serialization/SearchRequestWithAggsSerializationTests.cs index 0ee7a527df7..fab6cfe543b 100644 --- a/tests/Tests/Serialization/SearchRequestWithAggsSerializationTests.cs +++ b/tests/Tests/Serialization/SearchRequestWithAggsSerializationTests.cs @@ -6,7 +6,7 @@ namespace Tests.Serialization; -public class SearchRequestWithAggsSerializationTests : SerializerTestBase +public class SearchRequestDewscriptorWithAggregationsSerializationTests : SerializerTestBase { private const string SearchJson = @"{""aggregations"":{""my-terms-agg"":{""terms"":{""field"":""name""}}}}"; diff --git a/tests/Tests/Serialization/SearchSerializationTests.cs b/tests/Tests/Serialization/SearchSerializationTests.cs new file mode 100644 index 00000000000..0f742a3efbe --- /dev/null +++ b/tests/Tests/Serialization/SearchSerializationTests.cs @@ -0,0 +1,47 @@ +// 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. + +using System.Threading.Tasks; +using Elastic.Clients.Elasticsearch.Aggregations; +using Tests.Domain; +using VerifyXunit; + +namespace Tests.Serialization; + +[UsesVerify] +public class SearchSerializationTests : SerializerTestBase +{ + [U] + public async Task CanSerialize_SearchRequest_WithAggregations() + { + var searchRequest = new SearchRequest { Aggregations = new TermsAggregation("my-terms-agg") { Field = Infer.Field(f => f.Name) } }; + + var roundTripped = await RoundTripAndVerifyJsonAsync(searchRequest); + + roundTripped.Aggregations.Should().NotBeNull(); + roundTripped.Aggregations["my-terms-agg"].Should().NotBeNull(); + } + + [U] + public void CanDeserialize_SearchRequest_UsingAggs() + { + var json = @"{""aggs"":{""my-terms-agg"":{""terms"":{""field"":""name""}}}}"; + + var searchRequest = DeserializeJsonString(json); + + searchRequest.Aggregations.Should().NotBeNull(); + searchRequest.Aggregations["my-terms-agg"].Should().NotBeNull(); + } + + [U] + public void CanDeserialize_SearchRequest_UsingAggregations() + { + var json = @"{""aggregations"":{""my-terms-agg"":{""terms"":{""field"":""name""}}}}"; + + var searchRequest = DeserializeJsonString(json); + + searchRequest.Aggregations.Should().NotBeNull(); + searchRequest.Aggregations["my-terms-agg"].Should().NotBeNull(); + } +} diff --git a/tests/Tests/Serialization/SerializerTestBase.cs b/tests/Tests/Serialization/SerializerTestBase.cs index edb02bcdda8..be862d5a0dd 100644 --- a/tests/Tests/Serialization/SerializerTestBase.cs +++ b/tests/Tests/Serialization/SerializerTestBase.cs @@ -137,7 +137,7 @@ public static async Task SerializeAndVerifyJson(T data) return serialisedJson; } - public static async Task RoundTripAndVerifyJson(T data) + public static async Task RoundTripAndVerifyJsonAsync(T data) { var serialisedJson = await SerializeAndGetJsonStringAsync(data); await Verifier.VerifyJson(serialisedJson); diff --git a/tests/Tests/Serialization/SuggesterSerializationTests.cs b/tests/Tests/Serialization/SuggesterSerializationTests.cs index 68b143c567a..df97c7af681 100644 --- a/tests/Tests/Serialization/SuggesterSerializationTests.cs +++ b/tests/Tests/Serialization/SuggesterSerializationTests.cs @@ -24,7 +24,7 @@ public async Task Suggester_ObjectInitializer_SerializesCorrectly() } }; - var result = await RoundTripAndVerifyJson(suggester); + var result = await RoundTripAndVerifyJsonAsync(suggester); result.Text.Should().Be(suggester.Text); result.Suggesters.Should().HaveCount(2); diff --git a/tests/Tests/_VerifySnapshots/SearchSerializationTests.CanSerialize_SearchRequest_WithAggregations.verified.txt b/tests/Tests/_VerifySnapshots/SearchSerializationTests.CanSerialize_SearchRequest_WithAggregations.verified.txt new file mode 100644 index 00000000000..dc474c590a5 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/SearchSerializationTests.CanSerialize_SearchRequest_WithAggregations.verified.txt @@ -0,0 +1,9 @@ +{ + aggregations: { + my-terms-agg: { + terms: { + field: name + } + } + } +} \ No newline at end of file