Skip to content

Commit 75f0d7b

Browse files
committed
Add Indices and Aliases in BulkAlias API (#4816)
* Add Indices and Aliases in BulkAlias API This commit adds the aliases and indices options to add and remove alias operations for the bulk alias API. Closes #4721 (cherry picked from commit 126106c)
1 parent f1fc888 commit 75f0d7b

File tree

7 files changed

+105
-9
lines changed

7 files changed

+105
-9
lines changed

src/Nest/Indices/AliasManagement/Alias/Actions/AliasAdd.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System;
5+
using System;
6+
using System.Collections.Generic;
67
using System.Runtime.Serialization;
78
using Elasticsearch.Net.Utf8Json;
89

@@ -47,13 +48,34 @@ public AliasAddDescriptor Index<T>() where T : class
4748
return this;
4849
}
4950

51+
/// <inheritdoc cref="AliasAddOperation.Indices"/>
52+
public AliasAddDescriptor Indices(Indices indices)
53+
{
54+
Self.Add.Indices = indices;
55+
return this;
56+
}
57+
5058
/// <inheritdoc cref="AliasAddOperation.Alias"/>
5159
public AliasAddDescriptor Alias(string alias)
5260
{
5361
Self.Add.Alias = alias;
5462
return this;
5563
}
5664

65+
/// <inheritdoc cref="AliasAddOperation.Aliases"/>
66+
public AliasAddDescriptor Aliases(IEnumerable<string> aliases)
67+
{
68+
Self.Add.Aliases = aliases;
69+
return this;
70+
}
71+
72+
/// <inheritdoc cref="AliasAddOperation.Aliases"/>
73+
public AliasAddDescriptor Aliases(params string[] aliases)
74+
{
75+
Self.Add.Aliases = aliases;
76+
return this;
77+
}
78+
5779
/// <inheritdoc cref="AliasAddOperation.Routing"/>
5880
public AliasAddDescriptor Routing(string routing)
5981
{

src/Nest/Indices/AliasManagement/Alias/Actions/AliasAddOperation.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,27 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System.Runtime.Serialization;
5+
using System.Collections.Generic;
6+
using System.Runtime.Serialization;
7+
using Elasticsearch.Net.Utf8Json;
68

79
namespace Nest
810
{
911
public class AliasAddOperation
1012
{
1113
/// <summary>
12-
/// The name of the alias
14+
/// An alias to add.
15+
/// Multiple aliases can be specified with <see cref="Aliases"/>
1316
/// </summary>
1417
[DataMember(Name ="alias")]
1518
public string Alias { get; set; }
1619

20+
/// <summary>
21+
/// A collection of aliases to add
22+
/// </summary>
23+
[DataMember(Name ="aliases")]
24+
public IEnumerable<string> Aliases { get; set; }
25+
1726
/// <summary>
1827
/// Filter query used to limit the index alias.
1928
/// If specified, the index alias only applies to documents returned by the filter.
@@ -22,11 +31,19 @@ public class AliasAddOperation
2231
public QueryContainer Filter { get; set; }
2332

2433
/// <summary>
25-
/// The index to which to add the alias
34+
/// The index to which to add the alias.
35+
/// Multiple indices can be specified with <see cref="Indices"/>
2636
/// </summary>
2737
[DataMember(Name ="index")]
2838
public IndexName Index { get; set; }
2939

40+
/// <summary>
41+
/// The indices to which to add the alias
42+
/// </summary>
43+
[DataMember(Name = "indices")]
44+
[JsonFormatter(typeof(IndicesFormatter))]
45+
public Indices Indices { get; set; }
46+
3047
/// <inheritdoc cref="IAlias.IndexRouting"/>
3148
[DataMember(Name ="index_routing")]
3249
public string IndexRouting { get; set; }

src/Nest/Indices/AliasManagement/Alias/Actions/AliasRemove.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information
44

55
using System;
6+
using System.Collections.Generic;
67
using System.Runtime.Serialization;
78
using Elasticsearch.Net.Utf8Json;
89

@@ -26,28 +27,53 @@ public class AliasRemoveDescriptor : DescriptorBase<AliasRemoveDescriptor, IAlia
2627

2728
AliasRemoveOperation IAliasRemoveAction.Remove { get; set; }
2829

30+
/// <inheritdoc cref="AliasRemoveOperation.Index"/>
2931
public AliasRemoveDescriptor Index(string index)
3032
{
3133
Self.Remove.Index = index;
3234
return this;
3335
}
3436

37+
/// <inheritdoc cref="AliasRemoveOperation.Index"/>
3538
public AliasRemoveDescriptor Index(Type index)
3639
{
3740
Self.Remove.Index = index;
3841
return this;
3942
}
4043

44+
/// <inheritdoc cref="AliasRemoveOperation.Index"/>
4145
public AliasRemoveDescriptor Index<T>() where T : class
4246
{
4347
Self.Remove.Index = typeof(T);
4448
return this;
4549
}
4650

51+
/// <inheritdoc cref="AliasRemoveOperation.Indices"/>
52+
public AliasRemoveDescriptor Indices(Indices indices)
53+
{
54+
Self.Remove.Indices = indices;
55+
return this;
56+
}
57+
58+
/// <inheritdoc cref="AliasRemoveOperation.Alias"/>
4759
public AliasRemoveDescriptor Alias(string alias)
4860
{
4961
Self.Remove.Alias = alias;
5062
return this;
5163
}
64+
65+
/// <inheritdoc cref="AliasRemoveOperation.Aliases"/>
66+
public AliasRemoveDescriptor Aliases(IEnumerable<string> aliases)
67+
{
68+
Self.Remove.Aliases = aliases;
69+
return this;
70+
}
71+
72+
/// <inheritdoc cref="AliasRemoveOperation.Aliases"/>
73+
public AliasRemoveDescriptor Aliases(params string[] aliases)
74+
{
75+
Self.Remove.Aliases = aliases;
76+
return this;
77+
}
5278
}
5379
}

src/Nest/Indices/AliasManagement/Alias/Actions/AliasRemoveOperation.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,39 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System.Runtime.Serialization;
5+
using System.Collections.Generic;
6+
using System.Runtime.Serialization;
7+
using Elasticsearch.Net.Utf8Json;
68

79
namespace Nest
810
{
911
public class AliasRemoveOperation
1012
{
13+
/// <summary>
14+
/// An alias to remove.
15+
/// Multiple aliases can be specified with <see cref="Aliases"/>
16+
/// </summary>
1117
[DataMember(Name ="alias")]
1218
public string Alias { get; set; }
1319

20+
/// <summary>
21+
/// A collection of aliases to remove
22+
/// </summary>
23+
[DataMember(Name ="aliases")]
24+
public IEnumerable<string> Aliases { get; set; }
25+
26+
/// <summary>
27+
/// The index to which to add the alias.
28+
/// Multiple indices can be specified with <see cref="Indices"/>
29+
/// </summary>
1430
[DataMember(Name ="index")]
1531
public IndexName Index { get; set; }
32+
33+
/// <summary>
34+
/// The indices to which to add the alias
35+
/// </summary>
36+
[DataMember(Name = "indices")]
37+
[JsonFormatter(typeof(IndicesFormatter))]
38+
public Indices Indices { get; set; }
1639
}
1740
}

src/Nest/Indices/AliasManagement/Alias/Actions/IAliasAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using Elasticsearch.Net.Utf8Json;
5+
using Elasticsearch.Net.Utf8Json;
66
using Elasticsearch.Net.Utf8Json.Internal;
77

88

src/Nest/Indices/AliasManagement/Alias/BulkAliasRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System;
5+
using System;
66
using System.Collections.Generic;
77
using System.Runtime.Serialization;
88

tests/Tests/Indices/AliasManagement/Alias/AliasApiTests.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System;
5+
using System;
66
using System.Collections.Generic;
77
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
88
using Elasticsearch.Net;
@@ -28,15 +28,20 @@ public AliasApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluste
2828
{
2929
new Dictionary<string, object>
3030
{ { "add", new { alias = "alias", index = CallIsolatedValue, index_routing = "x", search_routing = "y" } } },
31+
new Dictionary<string, object>
32+
{ { "add", new { aliases = new [] { "alias1", "alias2" }, indices = new [] { CallIsolatedValue } } } },
3133
new Dictionary<string, object> { { "remove", new { alias = "alias", index = CallIsolatedValue } } },
34+
new Dictionary<string, object> { { "remove", new { aliases = new [] { "alias1", "alias2" }, indices = new[] { CallIsolatedValue } } } },
3235
}
3336
};
3437

3538
protected override int ExpectStatusCode => 200;
3639

3740
protected override Func<BulkAliasDescriptor, IBulkAliasRequest> Fluent => d => d
3841
.Add(a => a.Alias("alias").Index(CallIsolatedValue).IndexRouting("x").SearchRouting("y"))
39-
.Remove(a => a.Alias("alias").Index(CallIsolatedValue));
42+
.Add(a => a.Aliases("alias1", "alias2").Indices(CallIsolatedValue))
43+
.Remove(a => a.Alias("alias").Index(CallIsolatedValue))
44+
.Remove(a => a.Aliases("alias1", "alias2").Indices(CallIsolatedValue));
4045

4146
protected override HttpMethod HttpMethod => HttpMethod.POST;
4247

@@ -46,7 +51,10 @@ public AliasApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluste
4651
{
4752
new AliasAddAction
4853
{ Add = new AliasAddOperation { Alias = "alias", Index = CallIsolatedValue, IndexRouting = "x", SearchRouting = "y" } },
54+
new AliasAddAction
55+
{ Add = new AliasAddOperation { Aliases = new[] { "alias1", "alias2" }, Indices = CallIsolatedValue } },
4956
new AliasRemoveAction { Remove = new AliasRemoveOperation { Alias = "alias", Index = CallIsolatedValue } },
57+
new AliasRemoveAction { Remove = new AliasRemoveOperation { Aliases = new[] { "alias1", "alias2" }, Indices = CallIsolatedValue } },
5058
}
5159
};
5260

0 commit comments

Comments
 (0)