From c295e92ab6de7660c9499ef96cdb713e28d705fb Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Fri, 11 Oct 2024 15:01:50 +0100 Subject: [PATCH] Add `WithAlias` extensions for CreateIndexRequestDescriptor (#8373) * Add WithAlias extension methods for CreateIndexRequestDescriptor * Fix incorrect namespaces in manual code files * Remove params overloads (for now) --- .../CreateIndexRequestDescriptorExtensions.cs | 53 +++++++++++++++++++ .../IndexManagement/ExistsAliasResponse.cs | 2 +- .../ExistsIndexTemplateResponse.cs | 2 +- .../IndexManagement/ExistsTemplateResponse.cs | 2 +- 4 files changed, 56 insertions(+), 3 deletions(-) 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 00000000000..5b722d75ad6 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch.Shared/Api/Extensions/CreateIndexRequestDescriptorExtensions.cs @@ -0,0 +1,53 @@ +// 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; + } + + /// + /// 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; + } +} diff --git a/src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsAliasResponse.cs b/src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsAliasResponse.cs index e55df48a596..c5c1aa04369 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 90167ab564e..dc054dcc4c8 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 fd93d348d2f..a3362dc7e18 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