From d2580c53ce7e1537790ee98b51083e8b7edc4be3 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Mon, 6 Jun 2022 15:39:23 +0100 Subject: [PATCH 1/4] Generate initial types for mget --- .../_Generated/Api/ApiUrlsLookup.g.cs | 1 + .../_Generated/Api/MultiGetRequest.g.cs | 332 ++++++++++++++++++ .../_Generated/Api/MultiGetResponse.g.cs | 31 ++ .../Client/ElasticsearchClient.g.cs | 42 +++ .../_Generated/Types/GetResult.g.cs | 66 ++++ .../Types/Migration/MigrationFeature.g.cs | 12 - .../_Generated/Types/MultiGetError.g.cs | 41 +++ .../_Generated/Types/Operation.g.cs | 177 ++++++++++ .../_Generated/Types/ResponseItem.g.cs | 38 ++ 9 files changed, 728 insertions(+), 12 deletions(-) create mode 100644 src/Elastic.Clients.Elasticsearch/_Generated/Api/MultiGetRequest.g.cs create mode 100644 src/Elastic.Clients.Elasticsearch/_Generated/Api/MultiGetResponse.g.cs create mode 100644 src/Elastic.Clients.Elasticsearch/_Generated/Types/GetResult.g.cs create mode 100644 src/Elastic.Clients.Elasticsearch/_Generated/Types/MultiGetError.g.cs create mode 100644 src/Elastic.Clients.Elasticsearch/_Generated/Types/Operation.g.cs create mode 100644 src/Elastic.Clients.Elasticsearch/_Generated/Types/ResponseItem.g.cs diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/ApiUrlsLookup.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/ApiUrlsLookup.g.cs index 23f534cc5cd..8c1150269e5 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Api/ApiUrlsLookup.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/ApiUrlsLookup.g.cs @@ -215,6 +215,7 @@ internal static class ApiUrlsLookups internal static ApiUrls MachineLearningUpgradeJobSnapshot = new ApiUrls(new[] { "/_ml/anomaly_detectors/{job_id}/model_snapshots/{snapshot_id}/_upgrade" }); internal static ApiUrls MachineLearningValidateDetector = new ApiUrls(new[] { "/_ml/anomaly_detectors/_validate/detector" }); internal static ApiUrls MachineLearningValidate = new ApiUrls(new[] { "/_ml/anomaly_detectors/_validate" }); + internal static ApiUrls NoNamespaceMget = new ApiUrls(new[] { "/_mget", "/{index}/_mget" }); internal static ApiUrls NodesHotThreads = new ApiUrls(new[] { "/_nodes/hot_threads", "/_nodes/{node_id}/hot_threads" }); internal static ApiUrls NodesInfo = new ApiUrls(new[] { "/_nodes", "/_nodes/{node_id}", "/_nodes/{metric}", "/_nodes/{node_id}/{metric}" }); internal static ApiUrls NodesReloadSecureSettings = new ApiUrls(new[] { "/_nodes/reload_secure_settings", "/_nodes/{node_id}/reload_secure_settings" }); diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/MultiGetRequest.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/MultiGetRequest.g.cs new file mode 100644 index 00000000000..2f3f5f5e838 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/MultiGetRequest.g.cs @@ -0,0 +1,332 @@ +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Transport; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch +{ + public sealed class MultiGetRequestParameters : RequestParameters + { + [JsonIgnore] + public string? Preference { get => Q("preference"); set => Q("preference", value); } + + [JsonIgnore] + public bool? Realtime { get => Q("realtime"); set => Q("realtime", value); } + + [JsonIgnore] + public bool? Refresh { get => Q("refresh"); set => Q("refresh", value); } + + [JsonIgnore] + public Elastic.Clients.Elasticsearch.Routing? Routing { get => Q("routing"); set => Q("routing", value); } + + [JsonIgnore] + public Elastic.Clients.Elasticsearch.SourceConfigParam? Source { get => Q("_source"); set => Q("_source", value); } + + [JsonIgnore] + public Elastic.Clients.Elasticsearch.Fields? SourceExcludes { get => Q("_source_excludes"); set => Q("_source_excludes", value); } + + [JsonIgnore] + public Elastic.Clients.Elasticsearch.Fields? SourceIncludes { get => Q("_source_includes"); set => Q("_source_includes", value); } + + [JsonIgnore] + public Elastic.Clients.Elasticsearch.Fields? StoredFields { get => Q("stored_fields"); set => Q("stored_fields", value); } + } + + public partial class MultiGetRequest : PlainRequestBase + { + public MultiGetRequest() + { + } + + public MultiGetRequest(Elastic.Clients.Elasticsearch.IndexName? index) : base(r => r.Optional("index", index)) + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceMget; + protected override HttpMethod HttpMethod => HttpMethod.POST; + protected override bool SupportsBody => true; + [JsonIgnore] + public string? Preference { get => Q("preference"); set => Q("preference", value); } + + [JsonIgnore] + public bool? Realtime { get => Q("realtime"); set => Q("realtime", value); } + + [JsonIgnore] + public bool? Refresh { get => Q("refresh"); set => Q("refresh", value); } + + [JsonIgnore] + public Elastic.Clients.Elasticsearch.Routing? Routing { get => Q("routing"); set => Q("routing", value); } + + [JsonIgnore] + public Elastic.Clients.Elasticsearch.SourceConfigParam? Source { get => Q("_source"); set => Q("_source", value); } + + [JsonIgnore] + public Elastic.Clients.Elasticsearch.Fields? SourceExcludes { get => Q("_source_excludes"); set => Q("_source_excludes", value); } + + [JsonIgnore] + public Elastic.Clients.Elasticsearch.Fields? SourceIncludes { get => Q("_source_includes"); set => Q("_source_includes", value); } + + [JsonIgnore] + public Elastic.Clients.Elasticsearch.Fields? StoredFields { get => Q("stored_fields"); set => Q("stored_fields", value); } + + [JsonInclude] + [JsonPropertyName("docs")] + public IEnumerable? Docs { get; set; } + + [JsonInclude] + [JsonPropertyName("ids")] + public Elastic.Clients.Elasticsearch.Ids? Ids { get; set; } + } + + public sealed partial class MultiGetRequestDescriptor : RequestDescriptorBase, MultiGetRequestParameters> + { + internal MultiGetRequestDescriptor(Action> configure) => configure.Invoke(this); + public MultiGetRequestDescriptor() + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceMget; + protected override HttpMethod HttpMethod => HttpMethod.POST; + protected override bool SupportsBody => true; + public MultiGetRequestDescriptor Source(Elastic.Clients.Elasticsearch.SourceConfigParam? source) => Qs("_source", source); + public MultiGetRequestDescriptor SourceExcludes(Elastic.Clients.Elasticsearch.Fields? sourceExcludes) => Qs("_source_excludes", sourceExcludes); + public MultiGetRequestDescriptor SourceIncludes(Elastic.Clients.Elasticsearch.Fields? sourceIncludes) => Qs("_source_includes", sourceIncludes); + public MultiGetRequestDescriptor Preference(string? preference) => Qs("preference", preference); + public MultiGetRequestDescriptor Realtime(bool? realtime = true) => Qs("realtime", realtime); + public MultiGetRequestDescriptor Refresh(bool? refresh = true) => Qs("refresh", refresh); + public MultiGetRequestDescriptor Routing(Elastic.Clients.Elasticsearch.Routing? routing) => Qs("routing", routing); + public MultiGetRequestDescriptor StoredFields(Elastic.Clients.Elasticsearch.Fields? storedFields) => Qs("stored_fields", storedFields); + public MultiGetRequestDescriptor Index(Elastic.Clients.Elasticsearch.IndexName? index) + { + RouteValues.Optional("index", index); + return Self; + } + + private IEnumerable? DocsValue { get; set; } + + private OperationDescriptor DocsDescriptor { get; set; } + + private Action DocsDescriptorAction { get; set; } + + private Action[] DocsDescriptorActions { get; set; } + + private Elastic.Clients.Elasticsearch.Ids? IdsValue { get; set; } + + public MultiGetRequestDescriptor Docs(IEnumerable? docs) + { + DocsDescriptor = null; + DocsDescriptorAction = null; + DocsDescriptorActions = null; + DocsValue = docs; + return Self; + } + + public MultiGetRequestDescriptor Docs(OperationDescriptor descriptor) + { + DocsValue = null; + DocsDescriptorAction = null; + DocsDescriptorActions = null; + DocsDescriptor = descriptor; + return Self; + } + + public MultiGetRequestDescriptor Docs(Action configure) + { + DocsValue = null; + DocsDescriptor = null; + DocsDescriptorActions = null; + DocsDescriptorAction = configure; + return Self; + } + + public MultiGetRequestDescriptor Docs(params Action[] configure) + { + DocsValue = null; + DocsDescriptor = null; + DocsDescriptorAction = null; + DocsDescriptorActions = configure; + return Self; + } + + public MultiGetRequestDescriptor Ids(Elastic.Clients.Elasticsearch.Ids? ids) + { + IdsValue = ids; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + if (DocsDescriptor is not null) + { + writer.WritePropertyName("docs"); + JsonSerializer.Serialize(writer, DocsDescriptor, options); + } + else if (DocsDescriptorAction is not null) + { + writer.WritePropertyName("docs"); + JsonSerializer.Serialize(writer, new OperationDescriptor(DocsDescriptorAction), options); + } + else if (DocsDescriptorActions is not null) + { + writer.WritePropertyName("docs"); + writer.WriteStartArray(); + foreach (var action in DocsDescriptorActions) + { + JsonSerializer.Serialize(writer, new OperationDescriptor(action), options); + } + + writer.WriteEndArray(); + } + else if (DocsValue is not null) + { + writer.WritePropertyName("docs"); + JsonSerializer.Serialize(writer, DocsValue, options); + } + + if (IdsValue is not null) + { + writer.WritePropertyName("ids"); + JsonSerializer.Serialize(writer, IdsValue, options); + } + + writer.WriteEndObject(); + } + } + + public sealed partial class MultiGetRequestDescriptor : RequestDescriptorBase + { + internal MultiGetRequestDescriptor(Action configure) => configure.Invoke(this); + public MultiGetRequestDescriptor() + { + } + + internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceMget; + protected override HttpMethod HttpMethod => HttpMethod.POST; + protected override bool SupportsBody => true; + public MultiGetRequestDescriptor Source(Elastic.Clients.Elasticsearch.SourceConfigParam? source) => Qs("_source", source); + public MultiGetRequestDescriptor SourceExcludes(Elastic.Clients.Elasticsearch.Fields? sourceExcludes) => Qs("_source_excludes", sourceExcludes); + public MultiGetRequestDescriptor SourceIncludes(Elastic.Clients.Elasticsearch.Fields? sourceIncludes) => Qs("_source_includes", sourceIncludes); + public MultiGetRequestDescriptor Preference(string? preference) => Qs("preference", preference); + public MultiGetRequestDescriptor Realtime(bool? realtime = true) => Qs("realtime", realtime); + public MultiGetRequestDescriptor Refresh(bool? refresh = true) => Qs("refresh", refresh); + public MultiGetRequestDescriptor Routing(Elastic.Clients.Elasticsearch.Routing? routing) => Qs("routing", routing); + public MultiGetRequestDescriptor StoredFields(Elastic.Clients.Elasticsearch.Fields? storedFields) => Qs("stored_fields", storedFields); + public MultiGetRequestDescriptor Index(Elastic.Clients.Elasticsearch.IndexName? index) + { + RouteValues.Optional("index", index); + return Self; + } + + private IEnumerable? DocsValue { get; set; } + + private OperationDescriptor DocsDescriptor { get; set; } + + private Action DocsDescriptorAction { get; set; } + + private Action[] DocsDescriptorActions { get; set; } + + private Elastic.Clients.Elasticsearch.Ids? IdsValue { get; set; } + + public MultiGetRequestDescriptor Docs(IEnumerable? docs) + { + DocsDescriptor = null; + DocsDescriptorAction = null; + DocsDescriptorActions = null; + DocsValue = docs; + return Self; + } + + public MultiGetRequestDescriptor Docs(OperationDescriptor descriptor) + { + DocsValue = null; + DocsDescriptorAction = null; + DocsDescriptorActions = null; + DocsDescriptor = descriptor; + return Self; + } + + public MultiGetRequestDescriptor Docs(Action configure) + { + DocsValue = null; + DocsDescriptor = null; + DocsDescriptorActions = null; + DocsDescriptorAction = configure; + return Self; + } + + public MultiGetRequestDescriptor Docs(params Action[] configure) + { + DocsValue = null; + DocsDescriptor = null; + DocsDescriptorAction = null; + DocsDescriptorActions = configure; + return Self; + } + + public MultiGetRequestDescriptor Ids(Elastic.Clients.Elasticsearch.Ids? ids) + { + IdsValue = ids; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + if (DocsDescriptor is not null) + { + writer.WritePropertyName("docs"); + JsonSerializer.Serialize(writer, DocsDescriptor, options); + } + else if (DocsDescriptorAction is not null) + { + writer.WritePropertyName("docs"); + JsonSerializer.Serialize(writer, new OperationDescriptor(DocsDescriptorAction), options); + } + else if (DocsDescriptorActions is not null) + { + writer.WritePropertyName("docs"); + writer.WriteStartArray(); + foreach (var action in DocsDescriptorActions) + { + JsonSerializer.Serialize(writer, new OperationDescriptor(action), options); + } + + writer.WriteEndArray(); + } + else if (DocsValue is not null) + { + writer.WritePropertyName("docs"); + JsonSerializer.Serialize(writer, DocsValue, options); + } + + if (IdsValue is not null) + { + writer.WritePropertyName("ids"); + JsonSerializer.Serialize(writer, IdsValue, options); + } + + writer.WriteEndObject(); + } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Api/MultiGetResponse.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Api/MultiGetResponse.g.cs new file mode 100644 index 00000000000..d2e51d1378f --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Api/MultiGetResponse.g.cs @@ -0,0 +1,31 @@ +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Transport.Products.Elasticsearch; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch +{ + public sealed partial class MultiGetResponse : ElasticsearchResponseBase + { + [JsonInclude] + [JsonPropertyName("docs")] + public IReadOnlyCollection> Docs { get; init; } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Client/ElasticsearchClient.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Client/ElasticsearchClient.g.cs index 058b3fb514e..371ae9da4e3 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Client/ElasticsearchClient.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Client/ElasticsearchClient.g.cs @@ -1138,6 +1138,48 @@ public Task InfoAsync(Action configureReque return DoRequestAsync(descriptor); } + public MultiGetResponse MultiGet(MultiGetRequest request) + { + request.BeforeRequest(); + return DoRequest>(request); + } + + public Task> MultiGetAsync(MultiGetRequest request, CancellationToken cancellationToken = default) + { + request.BeforeRequest(); + return DoRequestAsync>(request, cancellationToken); + } + + public MultiGetResponse MultiGet() + { + var descriptor = new MultiGetRequestDescriptor(); + descriptor.BeforeRequest(); + return DoRequest, MultiGetResponse>(descriptor); + } + + public MultiGetResponse MultiGet(Action> configureRequest) + { + var descriptor = new MultiGetRequestDescriptor(); + configureRequest?.Invoke(descriptor); + descriptor.BeforeRequest(); + return DoRequest, MultiGetResponse>(descriptor); + } + + public Task> MultiGetAsync(CancellationToken cancellationToken = default) + { + var descriptor = new MultiGetRequestDescriptor(); + descriptor.BeforeRequest(); + return DoRequestAsync, MultiGetResponse>(descriptor); + } + + public Task> MultiGetAsync(Action> configureRequest, CancellationToken cancellationToken = default) + { + var descriptor = new MultiGetRequestDescriptor(); + configureRequest?.Invoke(descriptor); + descriptor.BeforeRequest(); + return DoRequestAsync, MultiGetResponse>(descriptor); + } + public OpenPointInTimeResponse OpenPointInTime(OpenPointInTimeRequest request) { request.BeforeRequest(); diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/GetResult.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/GetResult.g.cs new file mode 100644 index 00000000000..75de8c5ac10 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/GetResult.g.cs @@ -0,0 +1,66 @@ +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch +{ + public partial class GetResult + { + [JsonInclude] + [JsonPropertyName("_id")] + public string Id { get; init; } + + [JsonInclude] + [JsonPropertyName("_index")] + public string Index { get; init; } + + [JsonInclude] + [JsonPropertyName("_primary_term")] + public long? PrimaryTerm { get; init; } + + [JsonInclude] + [JsonPropertyName("_routing")] + public string? Routing { get; init; } + + [JsonInclude] + [JsonPropertyName("_seq_no")] + public long? SeqNo { get; init; } + + [JsonInclude] + [JsonPropertyName("_source")] + [SourceConverter] + public TDocument? Source { get; init; } + + [JsonInclude] + [JsonPropertyName("_version")] + public long? Version { get; init; } + + [JsonInclude] + [JsonPropertyName("fields")] + public Elastic.Clients.Elasticsearch.FieldValues? Fields { get; init; } + + [JsonInclude] + [JsonPropertyName("found")] + public bool Found { get; init; } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Migration/MigrationFeature.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Migration/MigrationFeature.g.cs index 79a7ea670eb..72faf353cdd 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Migration/MigrationFeature.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Migration/MigrationFeature.g.cs @@ -29,17 +29,5 @@ public partial class MigrationFeature [JsonInclude] [JsonPropertyName("feature_name")] public string FeatureName { get; init; } - - [JsonInclude] - [JsonPropertyName("indices")] - public IReadOnlyCollection Indices { get; init; } - - [JsonInclude] - [JsonPropertyName("migration_status")] - public Elastic.Clients.Elasticsearch.Migration.MigrationStatus MigrationStatus { get; init; } - - [JsonInclude] - [JsonPropertyName("minimum_index_version")] - public string MinimumIndexVersion { get; init; } } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/MultiGetError.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/MultiGetError.g.cs new file mode 100644 index 00000000000..1a501ab26ca --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/MultiGetError.g.cs @@ -0,0 +1,41 @@ +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch +{ + public partial class MultiGetError + { + [JsonInclude] + [JsonPropertyName("_id")] + public string Id { get; init; } + + [JsonInclude] + [JsonPropertyName("_index")] + public string Index { get; init; } + + [JsonInclude] + [JsonPropertyName("error")] + public Elastic.Clients.Elasticsearch.ErrorCause Error { get; init; } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Operation.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Operation.g.cs new file mode 100644 index 00000000000..5a2f0199ee0 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Operation.g.cs @@ -0,0 +1,177 @@ +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch +{ + public partial class Operation + { + [JsonInclude] + [JsonPropertyName("_id")] + public Elastic.Clients.Elasticsearch.Id Id { get; set; } + + [JsonInclude] + [JsonPropertyName("_index")] + public Elastic.Clients.Elasticsearch.IndexName? Index { get; set; } + + [JsonInclude] + [JsonPropertyName("_source")] + public Elastic.Clients.Elasticsearch.SourceConfig? Source { get; set; } + + [JsonInclude] + [JsonPropertyName("routing")] + public Elastic.Clients.Elasticsearch.Routing? Routing { get; set; } + + [JsonInclude] + [JsonPropertyName("stored_fields")] + public Elastic.Clients.Elasticsearch.Fields? StoredFields { get; set; } + + [JsonInclude] + [JsonPropertyName("version")] + public long? Version { get; set; } + + [JsonInclude] + [JsonPropertyName("version_type")] + public Elastic.Clients.Elasticsearch.VersionType? VersionType { get; set; } + } + + public sealed partial class OperationDescriptor : SerializableDescriptorBase + { + internal OperationDescriptor(Action configure) => configure.Invoke(this); + public OperationDescriptor() : base() + { + } + + private Elastic.Clients.Elasticsearch.Id IdValue { get; set; } + + private Elastic.Clients.Elasticsearch.IndexName? IndexValue { get; set; } + + private Elastic.Clients.Elasticsearch.SourceConfig? SourceValue { get; set; } + + private Elastic.Clients.Elasticsearch.Routing? RoutingValue { get; set; } + + private Elastic.Clients.Elasticsearch.Fields? StoredFieldsValue { get; set; } + + private long? VersionValue { get; set; } + + private Elastic.Clients.Elasticsearch.VersionType? VersionTypeValue { get; set; } + + public OperationDescriptor Id(Elastic.Clients.Elasticsearch.Id id) + { + IdValue = id; + return Self; + } + + public OperationDescriptor Index(Elastic.Clients.Elasticsearch.IndexName? index) + { + IndexValue = index; + return Self; + } + + public OperationDescriptor Source(Elastic.Clients.Elasticsearch.SourceConfig? source) + { + SourceValue = source; + return Self; + } + + public OperationDescriptor Routing(Elastic.Clients.Elasticsearch.Routing? routing) + { + RoutingValue = routing; + return Self; + } + + public OperationDescriptor StoredFields(Elastic.Clients.Elasticsearch.Fields? storedFields) + { + StoredFieldsValue = storedFields; + return Self; + } + + public OperationDescriptor StoredFields(Expression> storedFields) + { + StoredFieldsValue = storedFields; + return Self; + } + + public OperationDescriptor StoredFields(Expression> storedFields) + { + StoredFieldsValue = storedFields; + return Self; + } + + public OperationDescriptor Version(long? version) + { + VersionValue = version; + return Self; + } + + public OperationDescriptor VersionType(Elastic.Clients.Elasticsearch.VersionType? versionType) + { + VersionTypeValue = versionType; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + writer.WritePropertyName("_id"); + JsonSerializer.Serialize(writer, IdValue, options); + if (IndexValue is not null) + { + writer.WritePropertyName("_index"); + JsonSerializer.Serialize(writer, IndexValue, options); + } + + if (SourceValue is not null) + { + writer.WritePropertyName("_source"); + JsonSerializer.Serialize(writer, SourceValue, options); + } + + if (RoutingValue is not null) + { + writer.WritePropertyName("routing"); + JsonSerializer.Serialize(writer, RoutingValue, options); + } + + if (StoredFieldsValue is not null) + { + writer.WritePropertyName("stored_fields"); + JsonSerializer.Serialize(writer, StoredFieldsValue, options); + } + + if (VersionValue is not null) + { + writer.WritePropertyName("version"); + JsonSerializer.Serialize(writer, VersionValue, options); + } + + if (VersionTypeValue is not null) + { + writer.WritePropertyName("version_type"); + JsonSerializer.Serialize(writer, VersionTypeValue, options); + } + + writer.WriteEndObject(); + } + } +} \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/ResponseItem.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/ResponseItem.g.cs new file mode 100644 index 00000000000..541e4331b2d --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/ResponseItem.g.cs @@ -0,0 +1,38 @@ +// 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. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +using Elastic.Transport; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +#nullable restore +namespace Elastic.Clients.Elasticsearch +{ + public partial class ResponseItem : Union?, Elastic.Clients.Elasticsearch.MultiGetError?> + { + public ResponseItem(Elastic.Clients.Elasticsearch.GetResult? item) : base(item) + { + } + + public ResponseItem(Elastic.Clients.Elasticsearch.MultiGetError? item) : base(item) + { + } + } +} \ No newline at end of file From 1781760f0a525c03550dbdbafc86eb3ef8dde5eb Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 7 Jun 2022 16:28:23 +0100 Subject: [PATCH 2/4] Support ResponseItem union deserialization --- .../DefaultRequestResponseSerializer.cs | 1 + .../ResponseItemConverterFactory.cs | 97 +++++++++++++++++++ .../Serialization/UnionConverter.cs | 82 +++++++++++++++- 3 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/ResponseItemConverterFactory.cs diff --git a/src/Elastic.Clients.Elasticsearch/Serialization/DefaultRequestResponseSerializer.cs b/src/Elastic.Clients.Elasticsearch/Serialization/DefaultRequestResponseSerializer.cs index 77ed4e5ed2c..6f3d41b0a65 100644 --- a/src/Elastic.Clients.Elasticsearch/Serialization/DefaultRequestResponseSerializer.cs +++ b/src/Elastic.Clients.Elasticsearch/Serialization/DefaultRequestResponseSerializer.cs @@ -58,6 +58,7 @@ public DefaultRequestResponseSerializer(IElasticsearchClientSettings settings) new DictionaryConverter(settings), new PropertyNameConverter(settings), new IsADictionaryConverter(), + new ResponseItemConverterFactory(), new UnionConverter() }, PropertyNamingPolicy = JsonNamingPolicy.CamelCase diff --git a/src/Elastic.Clients.Elasticsearch/Serialization/ResponseItemConverterFactory.cs b/src/Elastic.Clients.Elasticsearch/Serialization/ResponseItemConverterFactory.cs new file mode 100644 index 00000000000..c622bf87365 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Serialization/ResponseItemConverterFactory.cs @@ -0,0 +1,97 @@ +// 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; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Elastic.Clients.Elasticsearch +{ + /// + /// A converter factory able to provide a converter to handle (de)serializing . + /// + internal sealed class ResponseItemConverterFactory : JsonConverterFactory + { + public override bool CanConvert(Type typeToConvert) => typeToConvert.IsGenericType && typeToConvert.GetGenericTypeDefinition() == typeof(ResponseItem<>); + + public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options) + { + var documentType = typeToConvert.GetGenericArguments()[0]; + + return (JsonConverter)Activator.CreateInstance( + typeof(ResponseItemConverter<>).MakeGenericType(documentType)); + } + + private sealed class ResponseItemConverter : JsonConverter> + { + public override ResponseItem? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + const string exceptionMessage = "Unable to deserialize union."; + var readerCopy = reader; + + Exception getResultException = null; + Exception errorException = null; + + // TODO - Review and optimise performance, possibly read-ahead to check for the error property and then deserialise + // accordingly is better? + + try + { + var result = JsonSerializer.Deserialize>(ref readerCopy, options); + + // If we have a version number, we can be sure this isn't an error + if (result is not null && result.Version is not null) + { + reader = readerCopy; // Ensure we swap the reader to reflect the data we have consumed. + return new ResponseItem(result); + } + } + catch (Exception ex) + { + getResultException = ex; + } + + try + { + var result = JsonSerializer.Deserialize(ref reader, options); + + if (result is not null && result.Error is not null) + { + return new ResponseItem(result); + } + } + catch (Exception ex) + { + errorException = ex; + } + + Exception innerException = null; + + if (errorException is not null && getResultException is not null) + { + innerException = new AggregateException(errorException, getResultException); + } + else if (errorException is not null) + { + innerException = errorException; + } + else if (getResultException is not null) + { + innerException = getResultException; + } + + if (innerException is not null) + { + throw new JsonException(exceptionMessage, innerException); + } + + throw new JsonException(exceptionMessage); + } + + // Not implemented as this type is read-only on responses. + public override void Write(Utf8JsonWriter writer, ResponseItem value, JsonSerializerOptions options) => + throw new NotImplementedException("We never expect to serialize an instance of ResponseItem as its a read-only response type."); + } + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Serialization/UnionConverter.cs b/src/Elastic.Clients.Elasticsearch/Serialization/UnionConverter.cs index 0e2505364bd..3c594e2489b 100644 --- a/src/Elastic.Clients.Elasticsearch/Serialization/UnionConverter.cs +++ b/src/Elastic.Clients.Elasticsearch/Serialization/UnionConverter.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; -using System.Runtime.Serialization; using System.Text.Json; using System.Text.Json.Serialization; using Elastic.Clients.Elasticsearch.Aggregations; @@ -13,7 +12,7 @@ namespace Elastic.Clients.Elasticsearch; internal sealed class UnionConverter : JsonConverterFactory { - private static readonly HashSet TypesToSkip = new HashSet + private static readonly HashSet TypesToSkip = new() { typeof(SourceConfig) }; @@ -47,11 +46,86 @@ public override JsonConverter CreateConverter( itemTwoType = type.BaseType.GetGenericArguments()[1]; } - var converter = (JsonConverter)Activator.CreateInstance(typeof(UnionConverterInner<,>).MakeGenericType(itemOneType, itemTwoType)); + JsonConverter converter; + + if (type.Name == typeof(Union<,>).Name) + { + converter = (JsonConverter)Activator.CreateInstance(typeof(UnionConverterInner<,>).MakeGenericType(itemOneType, itemTwoType)); + } + else + { + converter = (JsonConverter)Activator.CreateInstance(typeof(DerivedUnionConverterInner<,,>).MakeGenericType(type, itemOneType, itemTwoType)); + } return converter; } + private class DerivedUnionConverterInner : JsonConverter + { + public override TType? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + // TODO - Aggregate Exception if both fail + + var readerCopy = reader; + + try + { + var itemOne = JsonSerializer.Deserialize(ref readerCopy, options); + + if (itemOne is TItem1) + { + reader = readerCopy; + return (TType)Activator.CreateInstance(typeof(TType), itemOne); + } + } + catch + { + // TODO - Store for aggregate exception + } + + try + { + var itemTwo = JsonSerializer.Deserialize(ref reader, options); + + if (itemTwo is TItem2) + { + return (TType)Activator.CreateInstance(typeof(TType), itemTwo); + } + } + catch + { + // TODO - Store for aggregate exception + } + + throw new JsonException("Unable to deserialize union."); // TODO - Add inner aggregate exception. + } + + public override void Write(Utf8JsonWriter writer, TType value, + JsonSerializerOptions options) + { + if (value is null) + { + writer.WriteNullValue(); + return; + } + + //if (value.Item1 is not null) + //{ + // JsonSerializer.Serialize(writer, value.Item1, value.Item1.GetType(), options); + // return; + //} + + //if (value.Item2 is not null) + //{ + // JsonSerializer.Serialize(writer, value.Item2, value.Item2.GetType(), options); + // return; + //} + + throw new JsonException("TODO"); + //throw new JsonException("Invalid union type."); + } + } + private class UnionConverterInner : JsonConverter> { public override Union? Read(ref Utf8JsonReader reader, Type typeToConvert, @@ -72,7 +146,7 @@ public override void Write(Utf8JsonWriter writer, Union value, return; } - throw new SerializationException("Invalid union type"); + throw new JsonException("Invalid union type"); } } From ad27b09a607c43de8dc38426475d3e0b91c2a78f Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 7 Jun 2022 16:28:37 +0100 Subject: [PATCH 3/4] Add initial tests --- .../Types/TermsOrder.cs | 139 +++++++++--------- .../NodeSeeders/DefaultSeeder.cs | 5 +- tests/Tests.Domain/Developer.cs | 4 +- .../ConnectionSettingsExtensions.cs | 2 - .../Multiple/MultiGet/MultiGetApiTests.cs | 63 ++++++++ .../Documents/MGetSerialization.cs | 26 ++++ ...rialization.DeserializesError.verified.txt | 14 ++ ...ApiTests.VerifyDescriptorJson.verified.txt | 34 +++++ ...piTests.VerifyInitializerJson.verified.txt | 34 +++++ 9 files changed, 245 insertions(+), 76 deletions(-) create mode 100644 tests/Tests/Document/Multiple/MultiGet/MultiGetApiTests.cs create mode 100644 tests/Tests/Serialization/Documents/MGetSerialization.cs create mode 100644 tests/Tests/_VerifySnapshots/MGetSerialization.DeserializesError.verified.txt create mode 100644 tests/Tests/_VerifySnapshots/MultiGetSimplifiedApiTests.VerifyDescriptorJson.verified.txt create mode 100644 tests/Tests/_VerifySnapshots/MultiGetSimplifiedApiTests.VerifyInitializerJson.verified.txt diff --git a/src/Elastic.Clients.Elasticsearch/Types/TermsOrder.cs b/src/Elastic.Clients.Elasticsearch/Types/TermsOrder.cs index aeec3bd8cf7..44ff986a8f1 100644 --- a/src/Elastic.Clients.Elasticsearch/Types/TermsOrder.cs +++ b/src/Elastic.Clients.Elasticsearch/Types/TermsOrder.cs @@ -7,98 +7,97 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace Elastic.Clients.Elasticsearch +namespace Elastic.Clients.Elasticsearch; + +[JsonConverter(typeof(TermsOrderConverter))] +public readonly struct TermsOrder : IEquatable { - [JsonConverter(typeof(TermsOrderConverter))] - public readonly struct TermsOrder : IEquatable - { - public TermsOrder(string key, SortOrder order) => (Key, Order) = (key, order); + public TermsOrder(string key, SortOrder order) => (Key, Order) = (key, order); - public static TermsOrder CountAscending => new() { Key = "_count", Order = SortOrder.Asc }; - public static TermsOrder CountDescending => new() { Key = "_count", Order = SortOrder.Desc }; - public static TermsOrder KeyAscending => new() { Key = "_key", Order = SortOrder.Asc }; - public static TermsOrder KeyDescending => new() { Key = "_key", Order = SortOrder.Desc }; + public static TermsOrder CountAscending => new() { Key = "_count", Order = SortOrder.Asc }; + public static TermsOrder CountDescending => new() { Key = "_count", Order = SortOrder.Desc }; + public static TermsOrder KeyAscending => new() { Key = "_key", Order = SortOrder.Asc }; + public static TermsOrder KeyDescending => new() { Key = "_key", Order = SortOrder.Desc }; - public string Key { get; init; } - public SortOrder Order { get; init; } + public string Key { get; init; } + public SortOrder Order { get; init; } - public bool Equals(TermsOrder other) => Key == other.Key && Order == other.Order; - public override bool Equals(object obj) => obj is TermsOrder other && Equals(other); - public override int GetHashCode() => (Key, Order).GetHashCode(); - public static bool operator ==(TermsOrder lhs, TermsOrder rhs) => lhs.Equals(rhs); - public static bool operator !=(TermsOrder lhs, TermsOrder rhs) => !(lhs == rhs); - } + public bool Equals(TermsOrder other) => Key == other.Key && Order == other.Order; + public override bool Equals(object obj) => obj is TermsOrder other && Equals(other); + public override int GetHashCode() => (Key, Order).GetHashCode(); + public static bool operator ==(TermsOrder lhs, TermsOrder rhs) => lhs.Equals(rhs); + public static bool operator !=(TermsOrder lhs, TermsOrder rhs) => !(lhs == rhs); +} - internal sealed class TermsOrderConverter : JsonConverter +internal sealed class TermsOrderConverter : JsonConverter +{ + public override TermsOrder Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - public override TermsOrder Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - if (reader.TokenType != JsonTokenType.StartObject) - return default; + if (reader.TokenType != JsonTokenType.StartObject) + return default; - reader.Read(); - var key = reader.GetString(); + reader.Read(); + var key = reader.GetString(); - reader.Read(); - var valueString = reader.GetString(); - var value = valueString switch - { - "asc" => SortOrder.Asc, - "desc" => SortOrder.Desc, - _ => throw new JsonException("Unexpected sort order in JSON"), - }; + reader.Read(); + var valueString = reader.GetString(); + var value = valueString switch + { + "asc" => SortOrder.Asc, + "desc" => SortOrder.Desc, + _ => throw new JsonException("Unexpected sort order in JSON"), + }; - reader.Read(); + reader.Read(); - if (reader.TokenType != JsonTokenType.EndObject) - throw new JsonException("JSON did not conform to expected shape"); + if (reader.TokenType != JsonTokenType.EndObject) + throw new JsonException("JSON did not conform to expected shape"); - return new TermsOrder(key, value); + return new TermsOrder(key, value); + } + + public override void Write(Utf8JsonWriter writer, TermsOrder value, JsonSerializerOptions options) + { + if (string.IsNullOrEmpty(value.Key)) + { + writer.WriteNullValue(); + return; } - public override void Write(Utf8JsonWriter writer, TermsOrder value, JsonSerializerOptions options) + writer.WriteStartObject(); + writer.WritePropertyName(value.Key); + switch (value.Order) { - if (string.IsNullOrEmpty(value.Key)) - { - writer.WriteNullValue(); - return; - } - - writer.WriteStartObject(); - writer.WritePropertyName(value.Key); - switch (value.Order) - { - case SortOrder.Asc: - writer.WriteStringValue("asc"); - break; - case SortOrder.Desc: - writer.WriteStringValue("desc"); - break; - default: - throw new JsonException("Unknown sort order specified."); - } - writer.WriteEndObject(); + case SortOrder.Asc: + writer.WriteStringValue("asc"); + break; + case SortOrder.Desc: + writer.WriteStringValue("desc"); + break; + default: + throw new JsonException("Unknown sort order specified."); } + writer.WriteEndObject(); } +} - public sealed class TermsOrderDescriptor : PromiseDescriptor> - { - public TermsOrderDescriptor() : base(new List()) { } +public sealed class TermsOrderDescriptor : PromiseDescriptor> +{ + public TermsOrderDescriptor() : base(new List()) { } - internal TermsOrderDescriptor(Action configure) : this() => configure?.Invoke(this); + internal TermsOrderDescriptor(Action configure) : this() => configure?.Invoke(this); - public TermsOrderDescriptor CountAscending() => Assign(a => a.Add(TermsOrder.CountAscending)); + public TermsOrderDescriptor CountAscending() => Assign(a => a.Add(TermsOrder.CountAscending)); - public TermsOrderDescriptor CountDescending() => Assign(a => a.Add(TermsOrder.CountDescending)); + public TermsOrderDescriptor CountDescending() => Assign(a => a.Add(TermsOrder.CountDescending)); - public TermsOrderDescriptor KeyAscending() => Assign(a => a.Add(TermsOrder.KeyAscending)); + public TermsOrderDescriptor KeyAscending() => Assign(a => a.Add(TermsOrder.KeyAscending)); - public TermsOrderDescriptor KeyDescending() => Assign(a => a.Add(TermsOrder.KeyDescending)); + public TermsOrderDescriptor KeyDescending() => Assign(a => a.Add(TermsOrder.KeyDescending)); - public TermsOrderDescriptor Ascending(string key) => - string.IsNullOrWhiteSpace(key) ? this : Assign(key, (a, v) => a.Add(new TermsOrder { Key = v, Order = SortOrder.Asc })); + public TermsOrderDescriptor Ascending(string key) => + string.IsNullOrWhiteSpace(key) ? this : Assign(key, (a, v) => a.Add(new TermsOrder { Key = v, Order = SortOrder.Asc })); - public TermsOrderDescriptor Descending(string key) => - string.IsNullOrWhiteSpace(key) ? this : Assign(key, (a, v) => a.Add(new TermsOrder { Key = v, Order = SortOrder.Desc })); - } + public TermsOrderDescriptor Descending(string key) => + string.IsNullOrWhiteSpace(key) ? this : Assign(key, (a, v) => a.Add(new TermsOrder { Key = v, Order = SortOrder.Desc })); } diff --git a/tests/Tests.Core/ManagedElasticsearch/NodeSeeders/DefaultSeeder.cs b/tests/Tests.Core/ManagedElasticsearch/NodeSeeders/DefaultSeeder.cs index 94c421532b8..aa68eefb18b 100644 --- a/tests/Tests.Core/ManagedElasticsearch/NodeSeeders/DefaultSeeder.cs +++ b/tests/Tests.Core/ManagedElasticsearch/NodeSeeders/DefaultSeeder.cs @@ -270,8 +270,6 @@ public async Task CreateIndicesAsync() { mappings = new { - _routing = new { required = true }, - properties = new Dictionary { { "onlineHandle", new { type = "keyword" } } @@ -417,7 +415,8 @@ private async Task SeedIndexDataAsync() { var tasks = new Task[] { - Client.IndexManyAsync(Project.Projects) + Client.IndexManyAsync(Project.Projects), + Client.IndexManyAsync(Developer.Developers) }; await Task.WhenAll(tasks).ConfigureAwait(false); diff --git a/tests/Tests.Domain/Developer.cs b/tests/Tests.Domain/Developer.cs index 4efea319708..4cdd7001dee 100644 --- a/tests/Tests.Domain/Developer.cs +++ b/tests/Tests.Domain/Developer.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using Tests.Configuration; using System.Threading; +using System.Text.Json.Serialization; namespace Tests.Domain; @@ -17,6 +18,8 @@ public class Developer : Person //public GeoIp GeoIp { get; set; } public string IpAddress { get; set; } public string OnlineHandle { get; set; } + + [JsonIgnore] public string PrivateValue { get; set; } // @formatter:off — enable formatter after this line @@ -34,5 +37,4 @@ public class Developer : Person .RuleFor(p => p.IpAddress, p => p.Internet.Ip()); public static IList Developers { get; } = Generator.Clone().Generate(1000); - // @formatter:on — enable formatter after this line } diff --git a/tests/Tests.Domain/Extensions/ConnectionSettingsExtensions.cs b/tests/Tests.Domain/Extensions/ConnectionSettingsExtensions.cs index 94af73e8650..b26f9c640fc 100644 --- a/tests/Tests.Domain/Extensions/ConnectionSettingsExtensions.cs +++ b/tests/Tests.Domain/Extensions/ConnectionSettingsExtensions.cs @@ -27,8 +27,6 @@ public static ElasticsearchClientSettings ApplyDomainSettings(this Elasticsearch .DefaultMappingFor(map => map .IndexName("devs") - //.Ignore(p => p.PrivateValue) - //.PropertyName(p => p.OnlineHandle, "nickname") ) .DefaultMappingFor(map => map diff --git a/tests/Tests/Document/Multiple/MultiGet/MultiGetApiTests.cs b/tests/Tests/Document/Multiple/MultiGet/MultiGetApiTests.cs new file mode 100644 index 00000000000..bb71b5f12d8 --- /dev/null +++ b/tests/Tests/Document/Multiple/MultiGet/MultiGetApiTests.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Domain; +using Tests.Framework.EndpointTests; +using Tests.Framework.EndpointTests.TestState; + +namespace Tests.Document.Multiple.MultiGet; + +public class MultiGetSimplifiedApiTests + : ApiIntegrationTestBase, MultiGetRequestDescriptor, MultiGetRequest> +{ + private readonly IEnumerable _ids = Developer.Developers.Select(d => d.Id).Take(10); + + public MultiGetSimplifiedApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + + protected override bool ExpectIsValid => true; + + protected override bool VerifyJson => true; + + protected override int ExpectStatusCode => 200; + + protected override Action> Fluent => d => d + .Index(Infer.Index()) + .Docs(_ids.Select>(id => d => d.Id(id)).ToArray()); + + protected override HttpMethod HttpMethod => HttpMethod.POST; + + protected override MultiGetRequest Initializer => new(Infer.Index()) + { + Docs = _ids.Select(id => new Operation { Id = id }) + }; + + protected override bool SupportsDeserialization => false; + + protected override string ExpectedUrlPathAndQuery => "/devs/_mget"; + + protected override LazyResponses ClientUsage() => Calls( + (client, f) => client.MultiGet(f), + (client, f) => client.MultiGetAsync(f), + (client, r) => client.MultiGet(r), + (client, r) => client.MultiGetAsync(r) + ); + + protected override void ExpectResponse(MultiGetResponse response) + { + response.Docs.Should().NotBeEmpty().And.HaveCount(10); + + foreach (var document in response.Docs) + { + var getResult = document.Item1; + var error = document.Item2; + + getResult.Should().NotBeNull(); + getResult.Index.Should().NotBeNullOrWhiteSpace(); + getResult.Id.Should().NotBeNullOrWhiteSpace(); + getResult.Found.Should().BeTrue(); + + error.Should().BeNull(); + } + } +} diff --git a/tests/Tests/Serialization/Documents/MGetSerialization.cs b/tests/Tests/Serialization/Documents/MGetSerialization.cs new file mode 100644 index 00000000000..a116b463f91 --- /dev/null +++ b/tests/Tests/Serialization/Documents/MGetSerialization.cs @@ -0,0 +1,26 @@ +using System.Linq; +using System.Threading.Tasks; +using Tests.Domain; +using VerifyXunit; + +namespace Tests.Serialization.Documents; + +[UsesVerify] +public class MGetSerialization : SerializerTestBase +{ + [U] + public async Task DeserializesError() + { + var json = @"{""docs"":[{""_index"":""devs"",""_id"":""1001"",""error"":{""root_cause"":[{""type"":""routing_missing_exception"",""reason"":""routing is required for [devs]/[1001]"",""index_uuid"":""_na_"",""index"":""devs""}],""type"":""routing_missing_exception"",""reason"":""routing is required for [devs]/[1001]"",""index_uuid"":""_na_"",""index"":""devs""}}]}"; + + var stream = WrapInStream(json); + + var search = _requestResponseSerializer.Deserialize>(stream); + + search.Docs.Count.Should().Be(1); + var error = search.Docs.First().Item2; + error.Should().NotBeNull(); + + await Verifier.Verify(error); + } +} diff --git a/tests/Tests/_VerifySnapshots/MGetSerialization.DeserializesError.verified.txt b/tests/Tests/_VerifySnapshots/MGetSerialization.DeserializesError.verified.txt new file mode 100644 index 00000000000..17cb0f77232 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/MGetSerialization.DeserializesError.verified.txt @@ -0,0 +1,14 @@ +{ + Id: 1001, + Index: devs, + Error: { + Reason: routing is required for [devs]/[1001], + RootCause: [ + { + Reason: routing is required for [devs]/[1001], + Type: routing_missing_exception + } + ], + Type: routing_missing_exception + } +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/MultiGetSimplifiedApiTests.VerifyDescriptorJson.verified.txt b/tests/Tests/_VerifySnapshots/MultiGetSimplifiedApiTests.VerifyDescriptorJson.verified.txt new file mode 100644 index 00000000000..f5a37555c50 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/MultiGetSimplifiedApiTests.VerifyDescriptorJson.verified.txt @@ -0,0 +1,34 @@ +{ + docs: [ + { + _id: 1001 + }, + { + _id: 1002 + }, + { + _id: 1003 + }, + { + _id: 1004 + }, + { + _id: 1005 + }, + { + _id: 1006 + }, + { + _id: 1007 + }, + { + _id: 1008 + }, + { + _id: 1009 + }, + { + _id: 1010 + } + ] +} \ No newline at end of file diff --git a/tests/Tests/_VerifySnapshots/MultiGetSimplifiedApiTests.VerifyInitializerJson.verified.txt b/tests/Tests/_VerifySnapshots/MultiGetSimplifiedApiTests.VerifyInitializerJson.verified.txt new file mode 100644 index 00000000000..f5a37555c50 --- /dev/null +++ b/tests/Tests/_VerifySnapshots/MultiGetSimplifiedApiTests.VerifyInitializerJson.verified.txt @@ -0,0 +1,34 @@ +{ + docs: [ + { + _id: 1001 + }, + { + _id: 1002 + }, + { + _id: 1003 + }, + { + _id: 1004 + }, + { + _id: 1005 + }, + { + _id: 1006 + }, + { + _id: 1007 + }, + { + _id: 1008 + }, + { + _id: 1009 + }, + { + _id: 1010 + } + ] +} \ No newline at end of file From 78ff7f5aa09a201186f2c117a9b88b96602b001c Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 7 Jun 2022 16:42:38 +0100 Subject: [PATCH 4/4] Add license headers --- tests/Tests/Document/Multiple/MultiGet/MultiGetApiTests.cs | 4 ++++ tests/Tests/Serialization/Documents/MGetSerialization.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tests/Tests/Document/Multiple/MultiGet/MultiGetApiTests.cs b/tests/Tests/Document/Multiple/MultiGet/MultiGetApiTests.cs index bb71b5f12d8..138473ad5e8 100644 --- a/tests/Tests/Document/Multiple/MultiGet/MultiGetApiTests.cs +++ b/tests/Tests/Document/Multiple/MultiGet/MultiGetApiTests.cs @@ -1,3 +1,7 @@ +// 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; using System.Collections.Generic; using System.Linq; diff --git a/tests/Tests/Serialization/Documents/MGetSerialization.cs b/tests/Tests/Serialization/Documents/MGetSerialization.cs index a116b463f91..834faf7558d 100644 --- a/tests/Tests/Serialization/Documents/MGetSerialization.cs +++ b/tests/Tests/Serialization/Documents/MGetSerialization.cs @@ -1,3 +1,7 @@ +// 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.Linq; using System.Threading.Tasks; using Tests.Domain;