Skip to content

Commit 775030b

Browse files
committed
Add remove_index operation to Alias operations
Closes #2774 (cherry picked from commit 00a37cc)
1 parent d333cbf commit 775030b

File tree

5 files changed

+133
-9
lines changed

5 files changed

+133
-9
lines changed

src/Elasticsearch.sln

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26228.9
4+
VisualStudioVersion = 15.0.26430.6
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nest", "Nest\Nest.csproj", "{072BA7DA-7B60-407D-8B6E-95E3186BE70C}"
77
EndProject
@@ -29,7 +29,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiGenerator", "CodeGenerat
2929
EndProject
3030
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elasticsearch.Net", "Elasticsearch.Net\Elasticsearch.Net.csproj", "{E97CCF40-0BA6-43FE-9F2D-58D454134088}"
3131
EndProject
32-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "scripts", "..\build\scripts\scripts.fsproj", "{28328694-2598-44D3-BB25-8B6C3FBDD3EF}"
32+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "scripts", "..\build\scripts\scripts.fsproj", "{D6997ADC-E933-418E-831C-DE1A78897493}"
3333
EndProject
3434
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{37164C11-88EF-4428-803A-9AA24FB8B44D}"
3535
EndProject
@@ -53,8 +53,8 @@ Global
5353
{E97CCF40-0BA6-43FE-9F2D-58D454134088}.Debug|Any CPU.Build.0 = Debug|Any CPU
5454
{E97CCF40-0BA6-43FE-9F2D-58D454134088}.Release|Any CPU.ActiveCfg = Release|Any CPU
5555
{E97CCF40-0BA6-43FE-9F2D-58D454134088}.Release|Any CPU.Build.0 = Release|Any CPU
56-
{28328694-2598-44D3-BB25-8B6C3FBDD3EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57-
{28328694-2598-44D3-BB25-8B6C3FBDD3EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
56+
{D6997ADC-E933-418E-831C-DE1A78897493}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57+
{D6997ADC-E933-418E-831C-DE1A78897493}.Release|Any CPU.ActiveCfg = Release|Any CPU
5858
{37164C11-88EF-4428-803A-9AA24FB8B44D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
5959
{37164C11-88EF-4428-803A-9AA24FB8B44D}.Debug|Any CPU.Build.0 = Debug|Any CPU
6060
{37164C11-88EF-4428-803A-9AA24FB8B44D}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -69,7 +69,7 @@ Global
6969
EndGlobalSection
7070
GlobalSection(NestedProjects) = preSolution
7171
{56A87048-9065-459B-826D-3DF68B409845} = {93331BEE-0AA0-47B7-B1D2-BD5BD31634D1}
72-
{28328694-2598-44D3-BB25-8B6C3FBDD3EF} = {432D5575-2347-4D3C-BF8C-3E38410C46CA}
72+
{D6997ADC-E933-418E-831C-DE1A78897493} = {432D5575-2347-4D3C-BF8C-3E38410C46CA}
7373
{98400F59-4BA8-4534-9A78-9C7FA0B42901} = {93331BEE-0AA0-47B7-B1D2-BD5BD31634D1}
7474
EndGlobalSection
7575
EndGlobal
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace Nest
5+
{
6+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
7+
public interface IAliasRemoveIndexAction : IAliasAction
8+
{
9+
[JsonProperty("remove_index")]
10+
AliasRemoveIndexOperation RemoveIndex { get; set; }
11+
}
12+
13+
public class AliasRemoveIndexAction : IAliasRemoveIndexAction
14+
{
15+
public AliasRemoveIndexOperation RemoveIndex { get; set; }
16+
}
17+
18+
public class AliasRemoveIndexDescriptor : DescriptorBase<AliasRemoveIndexDescriptor, IAliasRemoveIndexAction>, IAliasRemoveIndexAction
19+
{
20+
AliasRemoveIndexOperation IAliasRemoveIndexAction.RemoveIndex { get; set; }
21+
22+
public AliasRemoveIndexDescriptor()
23+
{
24+
Self.RemoveIndex = new AliasRemoveIndexOperation();
25+
}
26+
27+
public AliasRemoveIndexDescriptor Index(IndexName index)
28+
{
29+
Self.RemoveIndex.Index = index;
30+
return this;
31+
}
32+
33+
public AliasRemoveIndexDescriptor Index(Type index)
34+
{
35+
Self.RemoveIndex.Index = index;
36+
return this;
37+
}
38+
39+
public AliasRemoveIndexDescriptor Index<T>() where T : class
40+
{
41+
Self.RemoveIndex.Index = typeof(T);
42+
return this;
43+
}
44+
}
45+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Nest
4+
{
5+
public class AliasRemoveIndexOperation
6+
{
7+
[JsonProperty("index")]
8+
public IndexName Index { get; set; }
9+
}
10+
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,31 @@
44

55
namespace Nest
66
{
7-
public partial interface IBulkAliasRequest
7+
public partial interface IBulkAliasRequest
88
{
99
[JsonProperty("actions")]
1010
IList<IAliasAction> Actions { get; set; }
1111
}
1212

13-
public partial class BulkAliasRequest
13+
public partial class BulkAliasRequest
1414
{
1515
public IList<IAliasAction> Actions { get; set; }
1616
}
1717

1818

1919
[DescriptorFor("IndicesUpdateAliases")]
20-
public partial class BulkAliasDescriptor
20+
public partial class BulkAliasDescriptor
2121
{
22-
public BulkAliasDescriptor Add(IAliasAction action) =>
22+
public BulkAliasDescriptor Add(IAliasAction action) =>
2323
Fluent.Assign<BulkAliasDescriptor, IBulkAliasRequest>(this, a=> a.Actions.AddIfNotNull(action));
2424

2525
IList<IAliasAction> IBulkAliasRequest.Actions { get; set; } = new List<IAliasAction>();
2626

2727
public BulkAliasDescriptor Add(Func<AliasAddDescriptor, IAliasAddAction> addSelector) => Add(addSelector?.Invoke(new AliasAddDescriptor()));
2828

2929
public BulkAliasDescriptor Remove(Func<AliasRemoveDescriptor, IAliasRemoveAction> removeSelector)=> Add(removeSelector?.Invoke(new AliasRemoveDescriptor()));
30+
31+
public IBulkAliasRequest RemoveIndex(Func<AliasRemoveIndexDescriptor, IAliasRemoveIndexAction> removeIndexSelector) =>
32+
Add(removeIndexSelector?.Invoke(new AliasRemoveIndexDescriptor()));
3033
}
3134
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Elasticsearch.Net;
4+
using Nest;
5+
using Tests.Framework;
6+
using Tests.Framework.Integration;
7+
using Tests.Framework.ManagedElasticsearch.Clusters;
8+
9+
namespace Tests.Indices.AliasManagement.Alias
10+
{
11+
public class AliasApiRemoveIndexTests : ApiIntegrationAgainstNewIndexTestBase<WritableCluster, IBulkAliasResponse, IBulkAliasRequest, BulkAliasDescriptor, BulkAliasRequest>
12+
{
13+
public AliasApiRemoveIndexTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
14+
15+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
16+
{
17+
foreach (var value in values.Values)
18+
{
19+
var createIndexResponse = client.CreateIndex(value + "-1", c => c);
20+
if (!createIndexResponse.IsValid)
21+
throw new Exception(createIndexResponse.DebugInformation);
22+
23+
createIndexResponse = client.CreateIndex(value + "-2", c => c);
24+
if (!createIndexResponse.IsValid)
25+
throw new Exception(createIndexResponse.DebugInformation);
26+
}
27+
}
28+
29+
protected override LazyResponses ClientUsage() => Calls(
30+
fluent: (client, f) => client.Alias(f),
31+
fluentAsync: (client, f) => client.AliasAsync(f),
32+
request: (client, r) => client.Alias(r),
33+
requestAsync: (client, r) => client.AliasAsync(r)
34+
);
35+
36+
protected override bool ExpectIsValid => true;
37+
protected override int ExpectStatusCode => 200;
38+
protected override HttpMethod HttpMethod => HttpMethod.POST;
39+
protected override string UrlPath => $"/_aliases";
40+
41+
protected override bool SupportsDeserialization => false;
42+
43+
protected override object ExpectJson => new
44+
{
45+
actions = new object[]
46+
{
47+
new Dictionary<string, object> { { "add", new { alias = CallIsolatedValue + "-1", index = CallIsolatedValue + "-2" } } },
48+
new Dictionary<string, object> { { "remove_index", new { index = CallIsolatedValue + "-1"} } },
49+
}
50+
};
51+
52+
protected override Func<BulkAliasDescriptor, IBulkAliasRequest> Fluent => d => d
53+
.Add(a=>a.Alias(CallIsolatedValue + "-1").Index(CallIsolatedValue + "-2"))
54+
.RemoveIndex(a => a.Index(CallIsolatedValue + "-1"))
55+
;
56+
57+
protected override BulkAliasRequest Initializer => new BulkAliasRequest
58+
{
59+
Actions = new List<IAliasAction>
60+
{
61+
new AliasAddAction { Add = new AliasAddOperation {Alias = CallIsolatedValue + "-1", Index = CallIsolatedValue + "-2"} },
62+
new AliasRemoveIndexAction {RemoveIndex = new AliasRemoveIndexOperation {Index = Infer.Index(CallIsolatedValue + "-1") }},
63+
}
64+
};
65+
}
66+
}

0 commit comments

Comments
 (0)