Skip to content

Commit c295e92

Browse files
stevejgordongithub-actions[bot]
authored andcommitted
Add WithAlias extensions for CreateIndexRequestDescriptor (#8373)
* Add WithAlias extension methods for CreateIndexRequestDescriptor * Fix incorrect namespaces in manual code files * Remove params overloads (for now)
1 parent a484f00 commit c295e92

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsAliasResponse.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Elastic.Transport.Products.Elasticsearch;
66

77
#if ELASTICSEARCH_SERVERLESS
8-
namespace Elastic.Clients.Elasticsearch.IndexManagement.Serverless;
8+
namespace Elastic.Clients.Elasticsearch.Serverless.IndexManagement;
99
#else
1010
namespace Elastic.Clients.Elasticsearch.IndexManagement;
1111
#endif

src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsIndexTemplateResponse.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Elastic.Transport.Products.Elasticsearch;
66

77
#if ELASTICSEARCH_SERVERLESS
8-
namespace Elastic.Clients.Elasticsearch.IndexManagement.Serverless;
8+
namespace Elastic.Clients.Elasticsearch.Serverless.IndexManagement;
99
#else
1010
namespace Elastic.Clients.Elasticsearch.IndexManagement;
1111
#endif

src/Elastic.Clients.Elasticsearch/_Shared/Api/IndexManagement/ExistsTemplateResponse.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Elastic.Transport.Products.Elasticsearch;
66

77
#if ELASTICSEARCH_SERVERLESS
8-
namespace Elastic.Clients.Elasticsearch.IndexManagement.Serverless;
8+
namespace Elastic.Clients.Elasticsearch.Serverless.IndexManagement;
99
#else
1010
namespace Elastic.Clients.Elasticsearch.IndexManagement;
1111
#endif

0 commit comments

Comments
 (0)