From 7abd1ead6bacd1525f00c2beb86a443320c5b719 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Wed, 2 Oct 2024 08:02:22 +0100 Subject: [PATCH 1/3] Add WithAlias extension methods for CreateIndexRequestDescriptor --- .../CreateIndexRequestDescriptorExtensions.cs | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/Elastic.Clients.Elasticsearch.Shared/Api/Extensions/CreateIndexRequestDescriptorExtensions.cs diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Api/Extensions/CreateIndexRequestDescriptorExtensions.cs b/src/Elastic.Clients.Elasticsearch.Shared/Api/Extensions/CreateIndexRequestDescriptorExtensions.cs new file mode 100644 index 0000000000..113dfe31de --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch.Shared/Api/Extensions/CreateIndexRequestDescriptorExtensions.cs @@ -0,0 +1,111 @@ +// 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; + +#if ELASTICSEARCH_SERVERLESS +namespace Elastic.Clients.Elasticsearch.Serverless.IndexManagement; +#else +namespace Elastic.Clients.Elasticsearch.IndexManagement; +#endif + +public static class CreateIndexRequestDescriptorExtensions +{ + /// + /// Add multiple aliases to the index at creation time. + /// + /// A descriptor for an index request. + /// The name of the alias. + /// The to allow fluent chaining of calls to configure the indexing request. + public static CreateIndexRequestDescriptor WithAlias(this CreateIndexRequestDescriptor descriptor, string aliasName) + { +#if NET8_0_OR_GREATER + ArgumentException.ThrowIfNullOrEmpty(aliasName); +#else + if (string.IsNullOrEmpty(aliasName)) + throw new ArgumentNullException(nameof(aliasName)); +#endif + + descriptor.Aliases(a => a.Add(aliasName, static _ => { })); + return descriptor; + } + + /// + /// Add multiple aliases to the index at creation time. + /// + /// A descriptor for an index request. + /// The names of the aliases. + /// The to allow fluent chaining of calls to configure the indexing request. + public static CreateIndexRequestDescriptor WithAliases(this CreateIndexRequestDescriptor descriptor, params ReadOnlySpan aliasNames) + { + foreach (var name in aliasNames) + descriptor.Aliases(a => a.Add(name, static _ => { })); + + return descriptor; + } + + /// + /// Add multiple aliases to the index at creation time. + /// + /// A descriptor for an index request. + /// The names of the aliases. + /// The to allow fluent chaining of calls to configure the indexing request. + public static CreateIndexRequestDescriptor WithAliases(this CreateIndexRequestDescriptor descriptor, params string[] aliasNames) + { + foreach (var name in aliasNames) + descriptor.Aliases(a => a.Add(name, static _ => { })); + + return descriptor; + } + + /// + /// Adds an alias to the index at creation time. + /// + /// The type representing documents stored in this index. + /// A fluent descriptor for an index request. + /// The name of the alias. + /// The to allow fluent chaining of calls to configure the indexing request. + public static CreateIndexRequestDescriptor WithAlias(this CreateIndexRequestDescriptor descriptor, string aliasName) + { +#if NET8_0_OR_GREATER + ArgumentException.ThrowIfNullOrEmpty(aliasName); +#else + if (string.IsNullOrEmpty(aliasName)) + throw new ArgumentNullException(nameof(aliasName)); +#endif + + descriptor.Aliases(a => a.Add(aliasName, static _ => { })); + return descriptor; + } + + /// + /// Add multiple aliases to the index at creation time. + /// + /// The type representing documents stored in this index. + /// A fluent descriptor for an index request. + /// The names of the aliases. + /// The to allow fluent chaining of calls to configure the indexing request. + public static CreateIndexRequestDescriptor WithAliases(this CreateIndexRequestDescriptor descriptor, params ReadOnlySpan aliasNames) + { + foreach (var name in aliasNames) + descriptor.Aliases(a => a.Add(name, static _ => { })); + + return descriptor; + } + + /// + /// Add multiple aliases to the index at creation time. + /// + /// The type representing documents stored in this index. + /// A fluent descriptor for an index request. + /// The names of the aliases. + /// The to allow fluent chaining of calls to configure the indexing request. + public static CreateIndexRequestDescriptor WithAliases(this CreateIndexRequestDescriptor descriptor, params string[] aliasNames) + { + foreach (var name in aliasNames) + descriptor.Aliases(a => a.Add(name, static _ => { })); + + return descriptor; + } +} From b25055c2e657a0c4cea30536fc6bca63544d8b80 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Wed, 2 Oct 2024 08:02:33 +0100 Subject: [PATCH 2/3] Fix incorrect namespaces in manual code files --- .../_Shared/Api/IndexManagement/ExistsAliasResponse.cs | 2 +- .../_Shared/Api/IndexManagement/ExistsIndexTemplateResponse.cs | 2 +- .../_Shared/Api/IndexManagement/ExistsTemplateResponse.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsAliasResponse.cs b/src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsAliasResponse.cs index e55df48a59..c5c1aa0436 100644 --- a/src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsAliasResponse.cs +++ b/src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsAliasResponse.cs @@ -5,7 +5,7 @@ using Elastic.Transport.Products.Elasticsearch; #if ELASTICSEARCH_SERVERLESS -namespace Elastic.Clients.Elasticsearch.IndexManagement.Serverless; +namespace Elastic.Clients.Elasticsearch.Serverless.IndexManagement; #else namespace Elastic.Clients.Elasticsearch.IndexManagement; #endif diff --git a/src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsIndexTemplateResponse.cs b/src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsIndexTemplateResponse.cs index 90167ab564..dc054dcc4c 100644 --- a/src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsIndexTemplateResponse.cs +++ b/src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsIndexTemplateResponse.cs @@ -5,7 +5,7 @@ using Elastic.Transport.Products.Elasticsearch; #if ELASTICSEARCH_SERVERLESS -namespace Elastic.Clients.Elasticsearch.IndexManagement.Serverless; +namespace Elastic.Clients.Elasticsearch.Serverless.IndexManagement; #else namespace Elastic.Clients.Elasticsearch.IndexManagement; #endif diff --git a/src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsTemplateResponse.cs b/src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsTemplateResponse.cs index fd93d348d2..a3362dc7e1 100644 --- a/src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsTemplateResponse.cs +++ b/src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsTemplateResponse.cs @@ -5,7 +5,7 @@ using Elastic.Transport.Products.Elasticsearch; #if ELASTICSEARCH_SERVERLESS -namespace Elastic.Clients.Elasticsearch.IndexManagement.Serverless; +namespace Elastic.Clients.Elasticsearch.Serverless.IndexManagement; #else namespace Elastic.Clients.Elasticsearch.IndexManagement; #endif From 1234954bfb47a792c9aa087c460cd385bdd7a273 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Thu, 3 Oct 2024 09:14:20 +0100 Subject: [PATCH 3/3] Remove params overloads (for now) --- .../CreateIndexRequestDescriptorExtensions.cs | 58 ------------------- 1 file changed, 58 deletions(-) diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Api/Extensions/CreateIndexRequestDescriptorExtensions.cs b/src/Elastic.Clients.Elasticsearch.Shared/Api/Extensions/CreateIndexRequestDescriptorExtensions.cs index 113dfe31de..5b722d75ad 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Api/Extensions/CreateIndexRequestDescriptorExtensions.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Api/Extensions/CreateIndexRequestDescriptorExtensions.cs @@ -31,34 +31,6 @@ public static CreateIndexRequestDescriptor WithAlias(this CreateIndexRequestDesc return descriptor; } - /// - /// Add multiple aliases to the index at creation time. - /// - /// A descriptor for an index request. - /// The names of the aliases. - /// The to allow fluent chaining of calls to configure the indexing request. - public static CreateIndexRequestDescriptor WithAliases(this CreateIndexRequestDescriptor descriptor, params ReadOnlySpan aliasNames) - { - foreach (var name in aliasNames) - descriptor.Aliases(a => a.Add(name, static _ => { })); - - return descriptor; - } - - /// - /// Add multiple aliases to the index at creation time. - /// - /// A descriptor for an index request. - /// The names of the aliases. - /// The to allow fluent chaining of calls to configure the indexing request. - public static CreateIndexRequestDescriptor WithAliases(this CreateIndexRequestDescriptor descriptor, params string[] aliasNames) - { - foreach (var name in aliasNames) - descriptor.Aliases(a => a.Add(name, static _ => { })); - - return descriptor; - } - /// /// Adds an alias to the index at creation time. /// @@ -78,34 +50,4 @@ public static CreateIndexRequestDescriptor WithAlias(this descriptor.Aliases(a => a.Add(aliasName, static _ => { })); return descriptor; } - - /// - /// Add multiple aliases to the index at creation time. - /// - /// The type representing documents stored in this index. - /// A fluent descriptor for an index request. - /// The names of the aliases. - /// The to allow fluent chaining of calls to configure the indexing request. - public static CreateIndexRequestDescriptor WithAliases(this CreateIndexRequestDescriptor descriptor, params ReadOnlySpan aliasNames) - { - foreach (var name in aliasNames) - descriptor.Aliases(a => a.Add(name, static _ => { })); - - return descriptor; - } - - /// - /// Add multiple aliases to the index at creation time. - /// - /// The type representing documents stored in this index. - /// A fluent descriptor for an index request. - /// The names of the aliases. - /// The to allow fluent chaining of calls to configure the indexing request. - public static CreateIndexRequestDescriptor WithAliases(this CreateIndexRequestDescriptor descriptor, params string[] aliasNames) - { - foreach (var name in aliasNames) - descriptor.Aliases(a => a.Add(name, static _ => { })); - - return descriptor; - } }