|
| 1 | +// Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System; |
| 6 | + |
| 7 | +#if ELASTICSEARCH_SERVERLESS |
| 8 | +namespace Elastic.Clients.Elasticsearch.Serverless.IndexManagement; |
| 9 | +#else |
| 10 | +namespace Elastic.Clients.Elasticsearch.IndexManagement; |
| 11 | +#endif |
| 12 | + |
| 13 | +public static class CreateIndexRequestDescriptorExtensions |
| 14 | +{ |
| 15 | + /// <summary> |
| 16 | + /// Add multiple aliases to the index at creation time. |
| 17 | + /// </summary> |
| 18 | + /// <param name="descriptor">A descriptor for an index request.</param> |
| 19 | + /// <param name="aliasName">The name of the alias.</param> |
| 20 | + /// <returns>The <see cref="CreateIndexRequestDescriptor"/> to allow fluent chaining of calls to configure the indexing request.</returns> |
| 21 | + public static CreateIndexRequestDescriptor WithAlias(this CreateIndexRequestDescriptor descriptor, string aliasName) |
| 22 | + { |
| 23 | +#if NET8_0_OR_GREATER |
| 24 | + ArgumentException.ThrowIfNullOrEmpty(aliasName); |
| 25 | +#else |
| 26 | + if (string.IsNullOrEmpty(aliasName)) |
| 27 | + throw new ArgumentNullException(nameof(aliasName)); |
| 28 | +#endif |
| 29 | + |
| 30 | + descriptor.Aliases(a => a.Add(aliasName, static _ => { })); |
| 31 | + return descriptor; |
| 32 | + } |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Adds an alias to the index at creation time. |
| 36 | + /// </summary> |
| 37 | + /// <typeparam name="TDocument">The type representing documents stored in this index.</typeparam> |
| 38 | + /// <param name="descriptor">A fluent descriptor for an index request.</param> |
| 39 | + /// <param name="aliasName">The name of the alias.</param> |
| 40 | + /// <returns>The <see cref="CreateIndexRequestDescriptor{TDocument}"/> to allow fluent chaining of calls to configure the indexing request.</returns> |
| 41 | + public static CreateIndexRequestDescriptor<TDocument> WithAlias<TDocument>(this CreateIndexRequestDescriptor<TDocument> descriptor, string aliasName) |
| 42 | + { |
| 43 | +#if NET8_0_OR_GREATER |
| 44 | + ArgumentException.ThrowIfNullOrEmpty(aliasName); |
| 45 | +#else |
| 46 | + if (string.IsNullOrEmpty(aliasName)) |
| 47 | + throw new ArgumentNullException(nameof(aliasName)); |
| 48 | +#endif |
| 49 | + |
| 50 | + descriptor.Aliases(a => a.Add(aliasName, static _ => { })); |
| 51 | + return descriptor; |
| 52 | + } |
| 53 | +} |
0 commit comments