Skip to content

Commit a67dfb8

Browse files
committed
Add support for the DELETE alias endpoint
1 parent 65cbf58 commit a67dfb8

12 files changed

+146
-33
lines changed

src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2638,12 +2638,12 @@ public DeleteIndexRequestParameters MasterTimeout(string master_timeout)
26382638
///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-aliases.html
26392639
///</pre>
26402640
///</summary>
2641-
public class IndicesDeleteAliasRequestParameters : FluentRequestParameters<IndicesDeleteAliasRequestParameters>
2641+
public class DeleteAliasRequestParameters : FluentRequestParameters<DeleteAliasRequestParameters>
26422642
{
26432643

26442644
internal string _timeout { get; set; }
26452645
///<summary>Explicit timestamp for the document</summary>
2646-
public IndicesDeleteAliasRequestParameters Timeout(string timeout)
2646+
public DeleteAliasRequestParameters Timeout(string timeout)
26472647
{
26482648
this._timeout = timeout;
26492649
this.AddQueryString("timeout", this._timeout);
@@ -2653,7 +2653,7 @@ public IndicesDeleteAliasRequestParameters Timeout(string timeout)
26532653

26542654
internal string _master_timeout { get; set; }
26552655
///<summary>Specify timeout for connection to master</summary>
2656-
public IndicesDeleteAliasRequestParameters MasterTimeout(string master_timeout)
2656+
public DeleteAliasRequestParameters MasterTimeout(string master_timeout)
26572657
{
26582658
this._master_timeout = master_timeout;
26592659
this.AddQueryString("master_timeout", this._master_timeout);

src/Elasticsearch.Net/ElasticsearchClient.Generated.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -11025,7 +11025,7 @@ public Task<ElasticsearchResponse<DynamicDictionary>> IndicesDeleteAsync(string
1102511025
///<para> - If T is of type byte[] deserialization will be shortcircuited</para>
1102611026
///<para> - If T is of type VoidResponse the response stream will be ignored completely</para>
1102711027
///</returns>
11028-
public ElasticsearchResponse<T> IndicesDeleteAlias<T>(string index, string name, Func<IndicesDeleteAliasRequestParameters, IndicesDeleteAliasRequestParameters> requestParameters = null)
11028+
public ElasticsearchResponse<T> IndicesDeleteAlias<T>(string index, string name, Func<DeleteAliasRequestParameters, DeleteAliasRequestParameters> requestParameters = null)
1102911029
{
1103011030
index.ThrowIfNullOrEmpty("index");
1103111031
name.ThrowIfNullOrEmpty("name");
@@ -11034,7 +11034,7 @@ public ElasticsearchResponse<T> IndicesDeleteAlias<T>(string index, string name,
1103411034

1103511035
if (requestParameters != null)
1103611036
{
11037-
requestParams = requestParameters(new IndicesDeleteAliasRequestParameters());
11037+
requestParams = requestParameters(new DeleteAliasRequestParameters());
1103811038
}
1103911039

1104011040

@@ -11061,7 +11061,7 @@ public ElasticsearchResponse<T> IndicesDeleteAlias<T>(string index, string name,
1106111061
///<para> - If T is of type byte[] deserialization will be shortcircuited</para>
1106211062
///<para> - If T is of type VoidResponse the response stream will be ignored completely</para>
1106311063
///</returns>
11064-
public Task<ElasticsearchResponse<T>> IndicesDeleteAliasAsync<T>(string index, string name, Func<IndicesDeleteAliasRequestParameters, IndicesDeleteAliasRequestParameters> requestParameters = null)
11064+
public Task<ElasticsearchResponse<T>> IndicesDeleteAliasAsync<T>(string index, string name, Func<DeleteAliasRequestParameters, DeleteAliasRequestParameters> requestParameters = null)
1106511065
{
1106611066
index.ThrowIfNullOrEmpty("index");
1106711067
name.ThrowIfNullOrEmpty("name");
@@ -11070,7 +11070,7 @@ public Task<ElasticsearchResponse<T>> IndicesDeleteAliasAsync<T>(string index, s
1107011070

1107111071
if (requestParameters != null)
1107211072
{
11073-
requestParams = requestParameters(new IndicesDeleteAliasRequestParameters());
11073+
requestParams = requestParameters(new DeleteAliasRequestParameters());
1107411074
}
1107511075

1107611076

@@ -11099,7 +11099,7 @@ public Task<ElasticsearchResponse<T>> IndicesDeleteAliasAsync<T>(string index, s
1109911099
///<para> - i.e result.Response.hits.hits[0].property.nested["nested_deeper"]</para>
1110011100
///<para> - can be safely dispatched to a nullable type even if intermediate properties do not exist</para>
1110111101
///</returns>
11102-
public ElasticsearchResponse<DynamicDictionary> IndicesDeleteAlias(string index, string name, Func<IndicesDeleteAliasRequestParameters, IndicesDeleteAliasRequestParameters> requestParameters = null)
11102+
public ElasticsearchResponse<DynamicDictionary> IndicesDeleteAlias(string index, string name, Func<DeleteAliasRequestParameters, DeleteAliasRequestParameters> requestParameters = null)
1110311103
{
1110411104
index.ThrowIfNullOrEmpty("index");
1110511105
name.ThrowIfNullOrEmpty("name");
@@ -11108,7 +11108,7 @@ public ElasticsearchResponse<DynamicDictionary> IndicesDeleteAlias(string index,
1110811108

1110911109
if (requestParameters != null)
1111011110
{
11111-
requestParams = requestParameters(new IndicesDeleteAliasRequestParameters());
11111+
requestParams = requestParameters(new DeleteAliasRequestParameters());
1111211112
}
1111311113

1111411114

@@ -11137,7 +11137,7 @@ public ElasticsearchResponse<DynamicDictionary> IndicesDeleteAlias(string index,
1113711137
///<para> - i.e result.Response.hits.hits[0].property.nested["nested_deeper"]</para>
1113811138
///<para> - can be safely dispatched to a nullable type even if intermediate properties do not exist</para>
1113911139
///</returns>
11140-
public Task<ElasticsearchResponse<DynamicDictionary>> IndicesDeleteAliasAsync(string index, string name, Func<IndicesDeleteAliasRequestParameters, IndicesDeleteAliasRequestParameters> requestParameters = null)
11140+
public Task<ElasticsearchResponse<DynamicDictionary>> IndicesDeleteAliasAsync(string index, string name, Func<DeleteAliasRequestParameters, DeleteAliasRequestParameters> requestParameters = null)
1114111141
{
1114211142
index.ThrowIfNullOrEmpty("index");
1114311143
name.ThrowIfNullOrEmpty("name");
@@ -11146,7 +11146,7 @@ public Task<ElasticsearchResponse<DynamicDictionary>> IndicesDeleteAliasAsync(st
1114611146

1114711147
if (requestParameters != null)
1114811148
{
11149-
requestParams = requestParameters(new IndicesDeleteAliasRequestParameters());
11149+
requestParams = requestParameters(new DeleteAliasRequestParameters());
1115011150
}
1115111151

1115211152

src/Elasticsearch.Net/IElasticsearchClient.Generated.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5769,7 +5769,7 @@ public interface IElasticsearchClient
57695769
///<para> - If T is of type VoidResponse the response stream will be ignored completely</para>
57705770
///</returns>
57715771

5772-
ElasticsearchResponse<T> IndicesDeleteAlias<T>(string index, string name, Func<IndicesDeleteAliasRequestParameters, IndicesDeleteAliasRequestParameters> requestParameters = null);
5772+
ElasticsearchResponse<T> IndicesDeleteAlias<T>(string index, string name, Func<DeleteAliasRequestParameters, DeleteAliasRequestParameters> requestParameters = null);
57735773

57745774
///<summary>Represents a DELETE on /{index}/_alias/{name}
57755775
///<para></para>Returns: A task that'll return an ElasticsearchResponse&lt;T&gt; holding the reponse body deserialized as T.
@@ -5788,7 +5788,7 @@ public interface IElasticsearchClient
57885788
///<para> - If T is of type VoidResponse the response stream will be ignored completely</para>
57895789
///</returns>
57905790

5791-
Task<ElasticsearchResponse<T>> IndicesDeleteAliasAsync<T>(string index, string name, Func<IndicesDeleteAliasRequestParameters, IndicesDeleteAliasRequestParameters> requestParameters = null);
5791+
Task<ElasticsearchResponse<T>> IndicesDeleteAliasAsync<T>(string index, string name, Func<DeleteAliasRequestParameters, DeleteAliasRequestParameters> requestParameters = null);
57925792

57935793
///<summary>Represents a DELETE on /{index}/_alias/{name}
57945794
///<para></para>Returns: ElasticsearchResponse&lt;T&gt; holding the response body deserialized as DynamicDictionary
@@ -5809,7 +5809,7 @@ public interface IElasticsearchClient
58095809
///<para> - can be safely dispatched to a nullable type even if intermediate properties do not exist</para>
58105810
///</returns>
58115811

5812-
ElasticsearchResponse<DynamicDictionary> IndicesDeleteAlias(string index, string name, Func<IndicesDeleteAliasRequestParameters, IndicesDeleteAliasRequestParameters> requestParameters = null);
5812+
ElasticsearchResponse<DynamicDictionary> IndicesDeleteAlias(string index, string name, Func<DeleteAliasRequestParameters, DeleteAliasRequestParameters> requestParameters = null);
58135813

58145814
///<summary>Represents a DELETE on /{index}/_alias/{name}
58155815
///<para></para>Returns: Task that'll return an ElasticsearchResponse&lt;T$gt; holding the response body deserialized as DynamicDictionary
@@ -5830,7 +5830,7 @@ public interface IElasticsearchClient
58305830
///<para> - can be safely dispatched to a nullable type even if intermediate properties do not exist</para>
58315831
///</returns>
58325832

5833-
Task<ElasticsearchResponse<DynamicDictionary>> IndicesDeleteAliasAsync(string index, string name, Func<IndicesDeleteAliasRequestParameters, IndicesDeleteAliasRequestParameters> requestParameters = null);
5833+
Task<ElasticsearchResponse<DynamicDictionary>> IndicesDeleteAliasAsync(string index, string name, Func<DeleteAliasRequestParameters, DeleteAliasRequestParameters> requestParameters = null);
58345834

58355835
///<summary>Represents a DELETE on /{index}/{type}/_mapping
58365836
///<para></para>Returns: ElasticsearchResponse&lt;T&gt; holding the reponse body deserialized as T.

src/Nest/DSL/DeleteAliasDescriptor.cs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Elasticsearch.Net;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
7+
namespace Nest
8+
{
9+
public interface IDeleteAliasRequest : IIndexNamePath<DeleteAliasRequestParameters>
10+
{
11+
}
12+
13+
internal static class DeleteAliasPathInfo
14+
{
15+
public static void Update(ElasticsearchPathInfo<DeleteAliasRequestParameters> pathInfo)
16+
{
17+
pathInfo.HttpMethod = PathInfoHttpMethod.DELETE;
18+
}
19+
}
20+
21+
public partial class DeleteAliasRequest : IndexNamePathBase<DeleteAliasRequestParameters>, IDeleteAliasRequest
22+
{
23+
public DeleteAliasRequest(string index, string name) : base(index, name) { }
24+
25+
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<DeleteAliasRequestParameters> pathInfo)
26+
{
27+
DeleteAliasPathInfo.Update(pathInfo);
28+
}
29+
}
30+
31+
[DescriptorFor("IndicesDeleteAlias")]
32+
public partial class DeleteAliasDescriptor<T>
33+
: IndexNamePathDescriptor<DeleteAliasDescriptor<T>, DeleteAliasRequestParameters, T>, IDeleteAliasRequest
34+
where T : class
35+
{
36+
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<DeleteAliasRequestParameters> pathInfo)
37+
{
38+
DeleteAliasPathInfo.Update(pathInfo);
39+
}
40+
}
41+
}

src/Nest/DSL/_Descriptors.generated.cs

+3-9
Original file line numberDiff line numberDiff line change
@@ -2443,32 +2443,26 @@ public DeleteIndexDescriptor MasterTimeout(string master_timeout)
24432443
///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-aliases.html
24442444
///</pre>
24452445
///</summary>
2446-
public partial class IndicesDeleteAliasDescriptor : BaseRequest<IndicesDeleteAliasRequestParameters>
2446+
public partial class DeleteAliasDescriptor<T>
24472447
{
24482448

24492449

24502450

24512451
///<summary>Explicit timestamp for the document</summary>
2452-
public IndicesDeleteAliasDescriptor Timeout(string timeout)
2452+
public DeleteAliasDescriptor<T> Timeout(string timeout)
24532453
{
24542454
this.Request.RequestParameters.Timeout(timeout);
24552455
return this;
24562456
}
24572457

24582458

24592459
///<summary>Specify timeout for connection to master</summary>
2460-
public IndicesDeleteAliasDescriptor MasterTimeout(string master_timeout)
2460+
public DeleteAliasDescriptor<T> MasterTimeout(string master_timeout)
24612461
{
24622462
this.Request.RequestParameters.MasterTimeout(master_timeout);
24632463
return this;
24642464
}
24652465

2466-
2467-
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<IndicesDeleteAliasRequestParameters> pathInfo)
2468-
{
2469-
throw new NotImplementedException();
2470-
}
2471-
24722466

24732467
}
24742468

src/Nest/DSL/_Requests.generated.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -2212,7 +2212,7 @@ public string MasterTimeout
22122212
///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-aliases.html
22132213
///</pre>
22142214
///</summary>
2215-
public partial class IndicesDeleteAliasRequest : BasePathRequest<IndicesDeleteAliasRequestParameters>
2215+
public partial class DeleteAliasRequest
22162216
{
22172217

22182218
///<summary>Explicit timestamp for the document</summary>
@@ -2230,12 +2230,6 @@ public string MasterTimeout
22302230
set { this.Request.RequestParameters.AddQueryString("master_timeout", value); }
22312231
}
22322232

2233-
2234-
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<IndicesDeleteAliasRequestParameters> pathInfo)
2235-
{
2236-
throw new NotImplementedException();
2237-
}
2238-
22392233
}
22402234

22412235

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace Nest
7+
{
8+
public interface IDeleteAliasResponse : IResponse
9+
{
10+
}
11+
12+
public class DeleteAliasResponse : BaseResponse, IDeleteAliasResponse
13+
{
14+
}
15+
}

src/Nest/ElasticClient-Aliases.cs

+34
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,40 @@ public Task<IPutAliasResponse> PutAliasAsync(Func<PutAliasDescriptor, PutAliasDe
173173
);
174174
}
175175

176+
public IDeleteAliasResponse DeleteAlias(IDeleteAliasRequest deleteAliasRequest)
177+
{
178+
return this.Dispatch<IDeleteAliasRequest, DeleteAliasRequestParameters, DeleteAliasResponse>(
179+
deleteAliasRequest,
180+
(p, d) => this.RawDispatch.IndicesDeleteAliasDispatch<DeleteAliasResponse>(p)
181+
);
182+
}
183+
184+
public Task<IDeleteAliasResponse> DeleteAliasAsync(IDeleteAliasRequest deleteAliasRequest)
185+
{
186+
return this.DispatchAsync<IDeleteAliasRequest, DeleteAliasRequestParameters, DeleteAliasResponse, IDeleteAliasResponse>(
187+
deleteAliasRequest,
188+
(p, d) => this.RawDispatch.IndicesDeleteAliasDispatchAsync<DeleteAliasResponse>(p)
189+
);
190+
}
191+
192+
public IDeleteAliasResponse DeleteAlias<T>(Func<DeleteAliasDescriptor<T>, DeleteAliasDescriptor<T>> deleteAliasDescriptor)
193+
where T : class
194+
{
195+
return this.Dispatch<DeleteAliasDescriptor<T>, DeleteAliasRequestParameters, DeleteAliasResponse>(
196+
deleteAliasDescriptor,
197+
(p, d) => this.RawDispatch.IndicesDeleteAliasDispatch<DeleteAliasResponse>(p)
198+
);
199+
}
200+
201+
public Task<IDeleteAliasResponse> DeleteAliasAsync<T>(Func<DeleteAliasDescriptor<T>, DeleteAliasDescriptor<T>> deleteAliasDescriptor)
202+
where T : class
203+
{
204+
return this.DispatchAsync<DeleteAliasDescriptor<T>, DeleteAliasRequestParameters, DeleteAliasResponse, IDeleteAliasResponse>(
205+
deleteAliasDescriptor,
206+
(p, d) => this.RawDispatch.IndicesDeleteAliasDispatchAsync<DeleteAliasResponse>(p)
207+
);
208+
}
209+
176210
/// <inheritdoc />
177211
private GetAliasesResponse DeserializeGetAliasesResponse(IElasticsearchResponse connectionStatus, Stream stream)
178212
{

src/Nest/IElasticClient.cs

+8
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,14 @@ Task<IGetResponse<T>> GetAsync<T>(IGetRequest getRequest)
10161016

10171017
Task<IPutAliasResponse> PutAliasAsync(Func<PutAliasDescriptor, PutAliasDescriptor> putAliasDescriptor);
10181018

1019+
IDeleteAliasResponse DeleteAlias(IDeleteAliasRequest deleteAliasRequest);
1020+
1021+
Task<IDeleteAliasResponse> DeleteAliasAsync(IDeleteAliasRequest deleteAliasRequest);
1022+
1023+
IDeleteAliasResponse DeleteAlias<T>(Func<DeleteAliasDescriptor<T>, DeleteAliasDescriptor<T>> deleteAliasDescriptor) where T : class;
1024+
1025+
Task<IDeleteAliasResponse> DeleteAliasAsync<T>(Func<DeleteAliasDescriptor<T>, DeleteAliasDescriptor<T>> deleteAliasDescriptor) where T : class;
1026+
10191027
/// <summary>
10201028
/// The optimize API allows to optimize one or more indices through an API. The optimize process basically optimizes
10211029
/// the index for faster search operations (and relates to the number of segments a Lucene index holds within each shard).

src/Nest/Nest.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
<Compile Include="Domain\Responses\CatResponse.cs" />
182182
<Compile Include="Domain\Responses\ClusterStatsResponse.cs" />
183183
<Compile Include="Domain\Responses\ClusterPendingTasksResponse.cs" />
184+
<Compile Include="Domain\Responses\DeleteAliasResponse.cs" />
184185
<Compile Include="Domain\Responses\ExplainResponse.cs" />
185186
<Compile Include="Domain\Responses\GetFieldMappingResponse.cs" />
186187
<Compile Include="Domain\Cat\ICatRecord.cs" />
@@ -226,6 +227,7 @@
226227
<Compile Include="DSL\ClusterPendingTasksDescriptor.cs" />
227228
<Compile Include="DSL\ClusterStatsDescriptor.cs" />
228229
<Compile Include="DSL\CatAliasesDescriptor.cs" />
230+
<Compile Include="DSL\DeleteAliasDescriptor.cs" />
229231
<Compile Include="DSL\GetRepositoryDescriptor.cs" />
230232
<Compile Include="DSL\Paths\RepositoryOptionalPathDescriptor.cs" />
231233
<Compile Include="DSL\PutAliasDescriptor.cs" />

src/Nest/RawDispatch.generated.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ internal Task<ElasticsearchResponse<T>> IndicesDeleteDispatchAsync<T>(Elasticsea
13301330
}
13311331

13321332

1333-
internal ElasticsearchResponse<T> IndicesDeleteAliasDispatch<T>(ElasticsearchPathInfo<IndicesDeleteAliasRequestParameters> pathInfo )
1333+
internal ElasticsearchResponse<T> IndicesDeleteAliasDispatch<T>(ElasticsearchPathInfo<DeleteAliasRequestParameters> pathInfo )
13341334
{
13351335
switch(pathInfo.HttpMethod)
13361336
{
@@ -1345,7 +1345,7 @@ internal ElasticsearchResponse<T> IndicesDeleteAliasDispatch<T>(ElasticsearchPat
13451345
}
13461346

13471347

1348-
internal Task<ElasticsearchResponse<T>> IndicesDeleteAliasDispatchAsync<T>(ElasticsearchPathInfo<IndicesDeleteAliasRequestParameters> pathInfo )
1348+
internal Task<ElasticsearchResponse<T>> IndicesDeleteAliasDispatchAsync<T>(ElasticsearchPathInfo<DeleteAliasRequestParameters> pathInfo )
13491349
{
13501350
switch(pathInfo.HttpMethod)
13511351
{

src/Tests/Nest.Tests.Integration/Indices/AliasTests.cs

+25
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,30 @@ public void PutSingleAlias()
299299
alias.Filter.Term.Field.Should().Be("name");
300300
alias.Filter.Term.Value.Should().Be("nest");
301301
}
302+
303+
[Test]
304+
public void DeleteSingleAlias()
305+
{
306+
var indexName = ElasticsearchConfiguration.NewUniqueIndexName();
307+
var aliasName = ElasticsearchConfiguration.NewUniqueIndexName();
308+
309+
var createIndexResponse = this.Client.CreateIndex(indexName);
310+
createIndexResponse.IsValid.Should().BeTrue();
311+
312+
var putAliasResponse = this.Client.PutAlias(a => a
313+
.Index(indexName)
314+
.Name(aliasName)
315+
);
316+
putAliasResponse.IsValid.Should().BeTrue();
317+
318+
var aliases = this.Client.GetAliasesPointingToIndex(indexName);
319+
aliases.Should().NotBeNull().And.HaveCount(1);
320+
321+
var deleteAliasResponse = this.Client.DeleteAlias(new DeleteAliasRequest(indexName, aliasName));
322+
deleteAliasResponse.IsValid.Should().BeTrue();
323+
324+
aliases = this.Client.GetAliasesPointingToIndex(indexName);
325+
aliases.Should().NotBeNull().And.HaveCount(0);
326+
}
302327
}
303328
}

0 commit comments

Comments
 (0)