-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
WithAlias
extensions for CreateIndexRequestDescriptor (#8373)
* Add WithAlias extension methods for CreateIndexRequestDescriptor * Fix incorrect namespaces in manual code files * Remove params overloads (for now)
- Loading branch information
1 parent
a484f00
commit c295e92
Showing
4 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...tic.Clients.Elasticsearch.Shared/Api/Extensions/CreateIndexRequestDescriptorExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// Add multiple aliases to the index at creation time. | ||
/// </summary> | ||
/// <param name="descriptor">A descriptor for an index request.</param> | ||
/// <param name="aliasName">The name of the alias.</param> | ||
/// <returns>The <see cref="CreateIndexRequestDescriptor"/> to allow fluent chaining of calls to configure the indexing request.</returns> | ||
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; | ||
} | ||
|
||
/// <summary> | ||
/// Adds an alias to the index at creation time. | ||
/// </summary> | ||
/// <typeparam name="TDocument">The type representing documents stored in this index.</typeparam> | ||
/// <param name="descriptor">A fluent descriptor for an index request.</param> | ||
/// <param name="aliasName">The name of the alias.</param> | ||
/// <returns>The <see cref="CreateIndexRequestDescriptor{TDocument}"/> to allow fluent chaining of calls to configure the indexing request.</returns> | ||
public static CreateIndexRequestDescriptor<TDocument> WithAlias<TDocument>(this CreateIndexRequestDescriptor<TDocument> 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters