From 61d98ab4d1727e3d54e38615d21fc124808539d8 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Mon, 8 Sep 2014 18:53:55 -0400 Subject: [PATCH 1/6] Add suport for the PUT alias endpoint --- .../RequestParameters.Generated.cs | 6 +- .../ElasticsearchClient.Generated.cs | 64 ++++++++-------- .../IElasticsearchClient.Generated.cs | 32 ++++---- src/Nest/DSL/PutAliasDescriptor.cs | 74 +++++++++++++++++++ src/Nest/DSL/_Descriptors.generated.cs | 12 +-- src/Nest/DSL/_Requests.generated.cs | 8 +- src/Nest/Domain/Responses/PutAliasResponse.cs | 15 ++++ src/Nest/ElasticClient-Aliases.cs | 35 +++++++++ src/Nest/IElasticClient.cs | 9 ++- src/Nest/Nest.csproj | 2 + src/Nest/RawDispatch.generated.cs | 4 +- .../Indices/AliasTests.cs | 28 +++++++ .../Core/Indices/Alias/AliasTests.cs | 32 ++++++++ .../Core/Indices/Alias/PutAlias.json | 8 ++ 14 files changed, 259 insertions(+), 70 deletions(-) create mode 100644 src/Nest/DSL/PutAliasDescriptor.cs create mode 100644 src/Nest/Domain/Responses/PutAliasResponse.cs create mode 100644 src/Tests/Nest.Tests.Unit/Core/Indices/Alias/AliasTests.cs create mode 100644 src/Tests/Nest.Tests.Unit/Core/Indices/Alias/PutAlias.json diff --git a/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs b/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs index c1a06503e5b..fb02913a431 100644 --- a/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs +++ b/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs @@ -3458,12 +3458,12 @@ public OptimizeRequestParameters Force(bool force) ///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-aliases.html /// /// - public class IndicesPutAliasRequestParameters : FluentRequestParameters + public class PutAliasRequestParameters : FluentRequestParameters { internal string _timeout { get; set; } ///Explicit timestamp for the document - public IndicesPutAliasRequestParameters Timeout(string timeout) + public PutAliasRequestParameters Timeout(string timeout) { this._timeout = timeout; this.AddQueryString("timeout", this._timeout); @@ -3473,7 +3473,7 @@ public IndicesPutAliasRequestParameters Timeout(string timeout) internal string _master_timeout { get; set; } ///Specify timeout for connection to master - public IndicesPutAliasRequestParameters MasterTimeout(string master_timeout) + public PutAliasRequestParameters MasterTimeout(string master_timeout) { this._master_timeout = master_timeout; this.AddQueryString("master_timeout", this._master_timeout); diff --git a/src/Elasticsearch.Net/ElasticsearchClient.Generated.cs b/src/Elasticsearch.Net/ElasticsearchClient.Generated.cs index a27b37cf95e..d0591e6562d 100644 --- a/src/Elasticsearch.Net/ElasticsearchClient.Generated.cs +++ b/src/Elasticsearch.Net/ElasticsearchClient.Generated.cs @@ -17658,7 +17658,7 @@ public Task> IndicesOptimizeGetAsync(st /// - If T is of type byte[] deserialization will be shortcircuited /// - If T is of type VoidResponse the response stream will be ignored completely /// - public ElasticsearchResponse IndicesPutAlias(string index, string name, object body, Func requestParameters = null) + public ElasticsearchResponse IndicesPutAlias(string index, string name, object body, Func requestParameters = null) { index.ThrowIfNullOrEmpty("index"); name.ThrowIfNullOrEmpty("name"); @@ -17667,7 +17667,7 @@ public ElasticsearchResponse IndicesPutAlias(string index, string name, ob if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -17695,7 +17695,7 @@ public ElasticsearchResponse IndicesPutAlias(string index, string name, ob /// - If T is of type byte[] deserialization will be shortcircuited /// - If T is of type VoidResponse the response stream will be ignored completely /// - public Task> IndicesPutAliasAsync(string index, string name, object body, Func requestParameters = null) + public Task> IndicesPutAliasAsync(string index, string name, object body, Func requestParameters = null) { index.ThrowIfNullOrEmpty("index"); name.ThrowIfNullOrEmpty("name"); @@ -17704,7 +17704,7 @@ public Task> IndicesPutAliasAsync(string index, stri if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -17734,7 +17734,7 @@ public Task> IndicesPutAliasAsync(string index, stri /// - i.e result.Response.hits.hits[0].property.nested["nested_deeper"] /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - public ElasticsearchResponse IndicesPutAlias(string index, string name, object body, Func requestParameters = null) + public ElasticsearchResponse IndicesPutAlias(string index, string name, object body, Func requestParameters = null) { index.ThrowIfNullOrEmpty("index"); name.ThrowIfNullOrEmpty("name"); @@ -17743,7 +17743,7 @@ public ElasticsearchResponse IndicesPutAlias(string index, st if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -17773,7 +17773,7 @@ public ElasticsearchResponse IndicesPutAlias(string index, st /// - i.e result.Response.hits.hits[0].property.nested["nested_deeper"] /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - public Task> IndicesPutAliasAsync(string index, string name, object body, Func requestParameters = null) + public Task> IndicesPutAliasAsync(string index, string name, object body, Func requestParameters = null) { index.ThrowIfNullOrEmpty("index"); name.ThrowIfNullOrEmpty("name"); @@ -17782,7 +17782,7 @@ public Task> IndicesPutAliasAsync(strin if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -17809,7 +17809,7 @@ public Task> IndicesPutAliasAsync(strin /// - If T is of type byte[] deserialization will be shortcircuited /// - If T is of type VoidResponse the response stream will be ignored completely /// - public ElasticsearchResponse IndicesPutAliasForAll(string name, object body, Func requestParameters = null) + public ElasticsearchResponse IndicesPutAliasForAll(string name, object body, Func requestParameters = null) { name.ThrowIfNullOrEmpty("name"); var url = "_alias/{0}".F(Encoded(name)); @@ -17817,7 +17817,7 @@ public ElasticsearchResponse IndicesPutAliasForAll(string name, object bod if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -17844,7 +17844,7 @@ public ElasticsearchResponse IndicesPutAliasForAll(string name, object bod /// - If T is of type byte[] deserialization will be shortcircuited /// - If T is of type VoidResponse the response stream will be ignored completely /// - public Task> IndicesPutAliasForAllAsync(string name, object body, Func requestParameters = null) + public Task> IndicesPutAliasForAllAsync(string name, object body, Func requestParameters = null) { name.ThrowIfNullOrEmpty("name"); var url = "_alias/{0}".F(Encoded(name)); @@ -17852,7 +17852,7 @@ public Task> IndicesPutAliasForAllAsync(string name, if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -17881,7 +17881,7 @@ public Task> IndicesPutAliasForAllAsync(string name, /// - i.e result.Response.hits.hits[0].property.nested["nested_deeper"] /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - public ElasticsearchResponse IndicesPutAliasForAll(string name, object body, Func requestParameters = null) + public ElasticsearchResponse IndicesPutAliasForAll(string name, object body, Func requestParameters = null) { name.ThrowIfNullOrEmpty("name"); var url = "_alias/{0}".F(Encoded(name)); @@ -17889,7 +17889,7 @@ public ElasticsearchResponse IndicesPutAliasForAll(string nam if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -17918,7 +17918,7 @@ public ElasticsearchResponse IndicesPutAliasForAll(string nam /// - i.e result.Response.hits.hits[0].property.nested["nested_deeper"] /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - public Task> IndicesPutAliasForAllAsync(string name, object body, Func requestParameters = null) + public Task> IndicesPutAliasForAllAsync(string name, object body, Func requestParameters = null) { name.ThrowIfNullOrEmpty("name"); var url = "_alias/{0}".F(Encoded(name)); @@ -17926,7 +17926,7 @@ public Task> IndicesPutAliasForAllAsync if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -17954,7 +17954,7 @@ public Task> IndicesPutAliasForAllAsync /// - If T is of type byte[] deserialization will be shortcircuited /// - If T is of type VoidResponse the response stream will be ignored completely /// - public ElasticsearchResponse IndicesPutAliasPost(string index, string name, object body, Func requestParameters = null) + public ElasticsearchResponse IndicesPutAliasPost(string index, string name, object body, Func requestParameters = null) { index.ThrowIfNullOrEmpty("index"); name.ThrowIfNullOrEmpty("name"); @@ -17963,7 +17963,7 @@ public ElasticsearchResponse IndicesPutAliasPost(string index, string name if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -17991,7 +17991,7 @@ public ElasticsearchResponse IndicesPutAliasPost(string index, string name /// - If T is of type byte[] deserialization will be shortcircuited /// - If T is of type VoidResponse the response stream will be ignored completely /// - public Task> IndicesPutAliasPostAsync(string index, string name, object body, Func requestParameters = null) + public Task> IndicesPutAliasPostAsync(string index, string name, object body, Func requestParameters = null) { index.ThrowIfNullOrEmpty("index"); name.ThrowIfNullOrEmpty("name"); @@ -18000,7 +18000,7 @@ public Task> IndicesPutAliasPostAsync(string index, if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -18030,7 +18030,7 @@ public Task> IndicesPutAliasPostAsync(string index, /// - i.e result.Response.hits.hits[0].property.nested["nested_deeper"] /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - public ElasticsearchResponse IndicesPutAliasPost(string index, string name, object body, Func requestParameters = null) + public ElasticsearchResponse IndicesPutAliasPost(string index, string name, object body, Func requestParameters = null) { index.ThrowIfNullOrEmpty("index"); name.ThrowIfNullOrEmpty("name"); @@ -18039,7 +18039,7 @@ public ElasticsearchResponse IndicesPutAliasPost(string index if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -18069,7 +18069,7 @@ public ElasticsearchResponse IndicesPutAliasPost(string index /// - i.e result.Response.hits.hits[0].property.nested["nested_deeper"] /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - public Task> IndicesPutAliasPostAsync(string index, string name, object body, Func requestParameters = null) + public Task> IndicesPutAliasPostAsync(string index, string name, object body, Func requestParameters = null) { index.ThrowIfNullOrEmpty("index"); name.ThrowIfNullOrEmpty("name"); @@ -18078,7 +18078,7 @@ public Task> IndicesPutAliasPostAsync(s if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -18105,7 +18105,7 @@ public Task> IndicesPutAliasPostAsync(s /// - If T is of type byte[] deserialization will be shortcircuited /// - If T is of type VoidResponse the response stream will be ignored completely /// - public ElasticsearchResponse IndicesPutAliasPostForAll(string name, object body, Func requestParameters = null) + public ElasticsearchResponse IndicesPutAliasPostForAll(string name, object body, Func requestParameters = null) { name.ThrowIfNullOrEmpty("name"); var url = "_alias/{0}".F(Encoded(name)); @@ -18113,7 +18113,7 @@ public ElasticsearchResponse IndicesPutAliasPostForAll(string name, object if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -18140,7 +18140,7 @@ public ElasticsearchResponse IndicesPutAliasPostForAll(string name, object /// - If T is of type byte[] deserialization will be shortcircuited /// - If T is of type VoidResponse the response stream will be ignored completely /// - public Task> IndicesPutAliasPostForAllAsync(string name, object body, Func requestParameters = null) + public Task> IndicesPutAliasPostForAllAsync(string name, object body, Func requestParameters = null) { name.ThrowIfNullOrEmpty("name"); var url = "_alias/{0}".F(Encoded(name)); @@ -18148,7 +18148,7 @@ public Task> IndicesPutAliasPostForAllAsync(string n if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -18177,7 +18177,7 @@ public Task> IndicesPutAliasPostForAllAsync(string n /// - i.e result.Response.hits.hits[0].property.nested["nested_deeper"] /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - public ElasticsearchResponse IndicesPutAliasPostForAll(string name, object body, Func requestParameters = null) + public ElasticsearchResponse IndicesPutAliasPostForAll(string name, object body, Func requestParameters = null) { name.ThrowIfNullOrEmpty("name"); var url = "_alias/{0}".F(Encoded(name)); @@ -18185,7 +18185,7 @@ public ElasticsearchResponse IndicesPutAliasPostForAll(string if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } @@ -18214,7 +18214,7 @@ public ElasticsearchResponse IndicesPutAliasPostForAll(string /// - i.e result.Response.hits.hits[0].property.nested["nested_deeper"] /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - public Task> IndicesPutAliasPostForAllAsync(string name, object body, Func requestParameters = null) + public Task> IndicesPutAliasPostForAllAsync(string name, object body, Func requestParameters = null) { name.ThrowIfNullOrEmpty("name"); var url = "_alias/{0}".F(Encoded(name)); @@ -18222,7 +18222,7 @@ public Task> IndicesPutAliasPostForAllA if (requestParameters != null) { - requestParams = requestParameters(new IndicesPutAliasRequestParameters()); + requestParams = requestParameters(new PutAliasRequestParameters()); } diff --git a/src/Elasticsearch.Net/IElasticsearchClient.Generated.cs b/src/Elasticsearch.Net/IElasticsearchClient.Generated.cs index 18a125495d3..86ff34f6069 100644 --- a/src/Elasticsearch.Net/IElasticsearchClient.Generated.cs +++ b/src/Elasticsearch.Net/IElasticsearchClient.Generated.cs @@ -9290,7 +9290,7 @@ public interface IElasticsearchClient /// - If T is of type VoidResponse the response stream will be ignored completely /// - ElasticsearchResponse IndicesPutAlias(string index, string name, object body, Func requestParameters = null); + ElasticsearchResponse IndicesPutAlias(string index, string name, object body, Func requestParameters = null); ///Represents a PUT on /{index}/_alias/{name} ///Returns: A task that'll return an ElasticsearchResponse<T> holding the reponse body deserialized as T. @@ -9310,7 +9310,7 @@ public interface IElasticsearchClient /// - If T is of type VoidResponse the response stream will be ignored completely /// - Task> IndicesPutAliasAsync(string index, string name, object body, Func requestParameters = null); + Task> IndicesPutAliasAsync(string index, string name, object body, Func requestParameters = null); ///Represents a PUT on /{index}/_alias/{name} ///Returns: ElasticsearchResponse<T> holding the response body deserialized as DynamicDictionary @@ -9332,7 +9332,7 @@ public interface IElasticsearchClient /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - ElasticsearchResponse IndicesPutAlias(string index, string name, object body, Func requestParameters = null); + ElasticsearchResponse IndicesPutAlias(string index, string name, object body, Func requestParameters = null); ///Represents a PUT on /{index}/_alias/{name} ///Returns: Task that'll return an ElasticsearchResponse<T$gt; holding the response body deserialized as DynamicDictionary @@ -9354,7 +9354,7 @@ public interface IElasticsearchClient /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - Task> IndicesPutAliasAsync(string index, string name, object body, Func requestParameters = null); + Task> IndicesPutAliasAsync(string index, string name, object body, Func requestParameters = null); ///Represents a PUT on /_alias/{name} ///Returns: ElasticsearchResponse<T> holding the reponse body deserialized as T. @@ -9373,7 +9373,7 @@ public interface IElasticsearchClient /// - If T is of type VoidResponse the response stream will be ignored completely /// - ElasticsearchResponse IndicesPutAliasForAll(string name, object body, Func requestParameters = null); + ElasticsearchResponse IndicesPutAliasForAll(string name, object body, Func requestParameters = null); ///Represents a PUT on /_alias/{name} ///Returns: A task that'll return an ElasticsearchResponse<T> holding the reponse body deserialized as T. @@ -9392,7 +9392,7 @@ public interface IElasticsearchClient /// - If T is of type VoidResponse the response stream will be ignored completely /// - Task> IndicesPutAliasForAllAsync(string name, object body, Func requestParameters = null); + Task> IndicesPutAliasForAllAsync(string name, object body, Func requestParameters = null); ///Represents a PUT on /_alias/{name} ///Returns: ElasticsearchResponse<T> holding the response body deserialized as DynamicDictionary @@ -9413,7 +9413,7 @@ public interface IElasticsearchClient /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - ElasticsearchResponse IndicesPutAliasForAll(string name, object body, Func requestParameters = null); + ElasticsearchResponse IndicesPutAliasForAll(string name, object body, Func requestParameters = null); ///Represents a PUT on /_alias/{name} ///Returns: Task that'll return an ElasticsearchResponse<T$gt; holding the response body deserialized as DynamicDictionary @@ -9434,7 +9434,7 @@ public interface IElasticsearchClient /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - Task> IndicesPutAliasForAllAsync(string name, object body, Func requestParameters = null); + Task> IndicesPutAliasForAllAsync(string name, object body, Func requestParameters = null); ///Represents a POST on /{index}/_alias/{name} ///Returns: ElasticsearchResponse<T> holding the reponse body deserialized as T. @@ -9454,7 +9454,7 @@ public interface IElasticsearchClient /// - If T is of type VoidResponse the response stream will be ignored completely /// - ElasticsearchResponse IndicesPutAliasPost(string index, string name, object body, Func requestParameters = null); + ElasticsearchResponse IndicesPutAliasPost(string index, string name, object body, Func requestParameters = null); ///Represents a POST on /{index}/_alias/{name} ///Returns: A task that'll return an ElasticsearchResponse<T> holding the reponse body deserialized as T. @@ -9474,7 +9474,7 @@ public interface IElasticsearchClient /// - If T is of type VoidResponse the response stream will be ignored completely /// - Task> IndicesPutAliasPostAsync(string index, string name, object body, Func requestParameters = null); + Task> IndicesPutAliasPostAsync(string index, string name, object body, Func requestParameters = null); ///Represents a POST on /{index}/_alias/{name} ///Returns: ElasticsearchResponse<T> holding the response body deserialized as DynamicDictionary @@ -9496,7 +9496,7 @@ public interface IElasticsearchClient /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - ElasticsearchResponse IndicesPutAliasPost(string index, string name, object body, Func requestParameters = null); + ElasticsearchResponse IndicesPutAliasPost(string index, string name, object body, Func requestParameters = null); ///Represents a POST on /{index}/_alias/{name} ///Returns: Task that'll return an ElasticsearchResponse<T$gt; holding the response body deserialized as DynamicDictionary @@ -9518,7 +9518,7 @@ public interface IElasticsearchClient /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - Task> IndicesPutAliasPostAsync(string index, string name, object body, Func requestParameters = null); + Task> IndicesPutAliasPostAsync(string index, string name, object body, Func requestParameters = null); ///Represents a POST on /_alias/{name} ///Returns: ElasticsearchResponse<T> holding the reponse body deserialized as T. @@ -9537,7 +9537,7 @@ public interface IElasticsearchClient /// - If T is of type VoidResponse the response stream will be ignored completely /// - ElasticsearchResponse IndicesPutAliasPostForAll(string name, object body, Func requestParameters = null); + ElasticsearchResponse IndicesPutAliasPostForAll(string name, object body, Func requestParameters = null); ///Represents a POST on /_alias/{name} ///Returns: A task that'll return an ElasticsearchResponse<T> holding the reponse body deserialized as T. @@ -9556,7 +9556,7 @@ public interface IElasticsearchClient /// - If T is of type VoidResponse the response stream will be ignored completely /// - Task> IndicesPutAliasPostForAllAsync(string name, object body, Func requestParameters = null); + Task> IndicesPutAliasPostForAllAsync(string name, object body, Func requestParameters = null); ///Represents a POST on /_alias/{name} ///Returns: ElasticsearchResponse<T> holding the response body deserialized as DynamicDictionary @@ -9577,7 +9577,7 @@ public interface IElasticsearchClient /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - ElasticsearchResponse IndicesPutAliasPostForAll(string name, object body, Func requestParameters = null); + ElasticsearchResponse IndicesPutAliasPostForAll(string name, object body, Func requestParameters = null); ///Represents a POST on /_alias/{name} ///Returns: Task that'll return an ElasticsearchResponse<T$gt; holding the response body deserialized as DynamicDictionary @@ -9598,7 +9598,7 @@ public interface IElasticsearchClient /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - Task> IndicesPutAliasPostForAllAsync(string name, object body, Func requestParameters = null); + Task> IndicesPutAliasPostForAllAsync(string name, object body, Func requestParameters = null); ///Represents a PUT on /{index}/{type}/_mapping ///Returns: ElasticsearchResponse<T> holding the reponse body deserialized as T. diff --git a/src/Nest/DSL/PutAliasDescriptor.cs b/src/Nest/DSL/PutAliasDescriptor.cs new file mode 100644 index 00000000000..03a4e6cab61 --- /dev/null +++ b/src/Nest/DSL/PutAliasDescriptor.cs @@ -0,0 +1,74 @@ +using Elasticsearch.Net; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IPutAliasRequest : IIndexOptionalNamePath + { + [JsonProperty("routing")] + string Routing { get; set; } + + [JsonProperty("filter")] + IFilterContainer Filter { get; set; } + } + + internal static class PutAliasPathInfo + { + public static void Update(ElasticsearchPathInfo pathInfo) + { + pathInfo.HttpMethod = PathInfoHttpMethod.PUT; + } + } + + public partial class PutAliasRequest : IndexOptionalNamePathBase, IPutAliasRequest + { + public PutAliasRequest(string name) : base(name) { } + + public PutAliasRequest(string index, string name) : base(index, name) { } + + public string Routing { get; set; } + + public IFilterContainer Filter { get; set; } + + protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) + { + PutAliasPathInfo.Update(pathInfo); + } + + } + + [DescriptorFor("IndicesPutAlias")] + public partial class PutAliasDescriptor + : IndexOptionalNamePathDescriptor, IPutAliasRequest + { + IPutAliasRequest Self { get { return this; } } + string IPutAliasRequest.Routing { get; set; } + IFilterContainer IPutAliasRequest.Filter { get; set; } + + public PutAliasDescriptor Routing(string routing) + { + Self.Routing = routing; + return this; + } + + public PutAliasDescriptor Filter(Func, FilterContainer> filterSelector) + where T : class + { + filterSelector.ThrowIfNull("filterSelector"); + Self.Filter = filterSelector(new FilterDescriptor()); + return this; + } + + protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) + { + PutAliasPathInfo.Update(pathInfo); + } + + } +} diff --git a/src/Nest/DSL/_Descriptors.generated.cs b/src/Nest/DSL/_Descriptors.generated.cs index e7c9fc57682..e79fa9ba05e 100644 --- a/src/Nest/DSL/_Descriptors.generated.cs +++ b/src/Nest/DSL/_Descriptors.generated.cs @@ -3195,13 +3195,13 @@ public OptimizeDescriptor Force(bool force = true) ///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-aliases.html /// /// - public partial class IndicesPutAliasDescriptor : BaseRequest + public partial class PutAliasDescriptor { ///Explicit timestamp for the document - public IndicesPutAliasDescriptor Timeout(string timeout) + public PutAliasDescriptor Timeout(string timeout) { this.Request.RequestParameters.Timeout(timeout); return this; @@ -3209,18 +3209,12 @@ public IndicesPutAliasDescriptor Timeout(string timeout) ///Specify timeout for connection to master - public IndicesPutAliasDescriptor MasterTimeout(string master_timeout) + public PutAliasDescriptor MasterTimeout(string master_timeout) { this.Request.RequestParameters.MasterTimeout(master_timeout); return this; } - - protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) - { - throw new NotImplementedException(); - } - } diff --git a/src/Nest/DSL/_Requests.generated.cs b/src/Nest/DSL/_Requests.generated.cs index 323635aa534..ceec210200d 100644 --- a/src/Nest/DSL/_Requests.generated.cs +++ b/src/Nest/DSL/_Requests.generated.cs @@ -2910,7 +2910,7 @@ public bool Force ///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-aliases.html /// /// - public partial class IndicesPutAliasRequest : BasePathRequest + public partial class PutAliasRequest { ///Explicit timestamp for the document @@ -2928,12 +2928,6 @@ public string MasterTimeout set { this.Request.RequestParameters.AddQueryString("master_timeout", value); } } - - protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) - { - throw new NotImplementedException(); - } - } diff --git a/src/Nest/Domain/Responses/PutAliasResponse.cs b/src/Nest/Domain/Responses/PutAliasResponse.cs new file mode 100644 index 00000000000..0048e2a6f79 --- /dev/null +++ b/src/Nest/Domain/Responses/PutAliasResponse.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public interface IPutAliasResponse : IResponse + { + } + + public class PutAliasResponse : BaseResponse, IPutAliasResponse + { + } +} diff --git a/src/Nest/ElasticClient-Aliases.cs b/src/Nest/ElasticClient-Aliases.cs index 6ed75bbfe0a..62b3f1968b2 100644 --- a/src/Nest/ElasticClient-Aliases.cs +++ b/src/Nest/ElasticClient-Aliases.cs @@ -137,6 +137,41 @@ public Task GetAliasesAsync(IGetAliasesRequest getAliasesRe ); } + /// + public IPutAliasResponse PutAlias(IPutAliasRequest putAliasRequest) + { + return this.Dispatch( + putAliasRequest, + (p, d) => this.RawDispatch.IndicesPutAliasDispatch(p, d) + ); + } + + /// + public Task PutAliasAsync(IPutAliasRequest putAliasRequest) + { + return this.DispatchAsync( + putAliasRequest, + (p, d) => this.RawDispatch.IndicesPutAliasDispatchAsync(p, d) + ); + } + + /// + public IPutAliasResponse PutAlias(Func putAliasDescriptor) + { + return this.Dispatch( + putAliasDescriptor, + (p, d) => this.RawDispatch.IndicesPutAliasDispatch(p, d) + ); + } + + /// + public Task PutAliasAsync(Func putAliasDescriptor) + { + return this.DispatchAsync( + putAliasDescriptor, + (p, d) => this.RawDispatch.IndicesPutAliasDispatchAsync(p, d) + ); + } /// private GetAliasesResponse DeserializeGetAliasesResponse(IElasticsearchResponse connectionStatus, Stream stream) diff --git a/src/Nest/IElasticClient.cs b/src/Nest/IElasticClient.cs index 2c323b21dd7..53c89ca49d7 100644 --- a/src/Nest/IElasticClient.cs +++ b/src/Nest/IElasticClient.cs @@ -1007,7 +1007,14 @@ Task> GetAsync(IGetRequest getRequest) /// Task GetAliasesAsync(IGetAliasesRequest getAliasesRequest); - + + IPutAliasResponse PutAlias(IPutAliasRequest putAliasRequest); + + Task PutAliasAsync(IPutAliasRequest putAliasRequest); + + IPutAliasResponse PutAlias(Func putAliasDescriptor); + + Task PutAliasAsync(Func putAliasDescriptor); /// /// The optimize API allows to optimize one or more indices through an API. The optimize process basically optimizes diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index b51fab136b6..b4ec46ebe0c 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -187,6 +187,7 @@ + @@ -227,6 +228,7 @@ + diff --git a/src/Nest/RawDispatch.generated.cs b/src/Nest/RawDispatch.generated.cs index ae8ccdde365..2fee993cb1e 100644 --- a/src/Nest/RawDispatch.generated.cs +++ b/src/Nest/RawDispatch.generated.cs @@ -2010,7 +2010,7 @@ internal Task> IndicesOptimizeDispatchAsync(Elastics } - internal ElasticsearchResponse IndicesPutAliasDispatch(ElasticsearchPathInfo pathInfo , object body) + internal ElasticsearchResponse IndicesPutAliasDispatch(ElasticsearchPathInfo pathInfo , object body) { switch(pathInfo.HttpMethod) { @@ -2037,7 +2037,7 @@ internal ElasticsearchResponse IndicesPutAliasDispatch(ElasticsearchPathIn } - internal Task> IndicesPutAliasDispatchAsync(ElasticsearchPathInfo pathInfo , object body) + internal Task> IndicesPutAliasDispatchAsync(ElasticsearchPathInfo pathInfo , object body) { switch(pathInfo.HttpMethod) { diff --git a/src/Tests/Nest.Tests.Integration/Indices/AliasTests.cs b/src/Tests/Nest.Tests.Integration/Indices/AliasTests.cs index 7759a71113d..165782a35a6 100644 --- a/src/Tests/Nest.Tests.Integration/Indices/AliasTests.cs +++ b/src/Tests/Nest.Tests.Integration/Indices/AliasTests.cs @@ -271,5 +271,33 @@ public void AliasWithFilterPointingToIndex() term.Field.Should().Be("foo"); term.Value.Should().Be("bar"); } + + [Test] + public void PutSingleAlias() + { + var indexName = ElasticsearchConfiguration.NewUniqueIndexName(); + var aliasName = ElasticsearchConfiguration.NewUniqueIndexName(); + + var createIndexResponse = this.Client.CreateIndex(indexName); + createIndexResponse.IsValid.Should().BeTrue(); + + var result = this.Client.PutAlias(a => a + .Index(indexName) + .Name(aliasName) + .Filter(f => f + .Term(p => p.Name, "nest") + ) + ); + + result.IsValid.Should().BeTrue(); + + var aliases = this.Client.GetAliasesPointingToIndex(indexName); + aliases.Should().NotBeNull().And.HaveCount(1); + var alias = aliases.First(); + alias.Name.ShouldAllBeEquivalentTo(aliasName); + alias.Filter.Should().NotBeNull(); + alias.Filter.Term.Field.Should().Be("name"); + alias.Filter.Term.Value.Should().Be("nest"); + } } } \ No newline at end of file diff --git a/src/Tests/Nest.Tests.Unit/Core/Indices/Alias/AliasTests.cs b/src/Tests/Nest.Tests.Unit/Core/Indices/Alias/AliasTests.cs new file mode 100644 index 00000000000..c8a81156387 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Core/Indices/Alias/AliasTests.cs @@ -0,0 +1,32 @@ +using FluentAssertions; +using Nest.Tests.MockData.Domain; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Nest.Tests.Unit.Core.Indices.Alias +{ + [TestFixture] + public class AliasTests : BaseJsonTests + { + [Test] + public void PutAlias() + { + var result = this._client.PutAlias(a => a + .Name("my-alias") + .Index("my-index") + .Routing("12") + .Filter(f => f + .Term(t => t.Name, "nest") + ) + ); + + Assert.IsTrue(result.ConnectionStatus.RequestUrl.EndsWith("/my-index/_alias/my-alias")); + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Core/Indices/Alias/PutAlias.json b/src/Tests/Nest.Tests.Unit/Core/Indices/Alias/PutAlias.json new file mode 100644 index 00000000000..5140bfcbce5 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Core/Indices/Alias/PutAlias.json @@ -0,0 +1,8 @@ +{ + "routing": "12", + "filter": { + "term": { + "name": "nest" + } + } +} \ No newline at end of file From 51aa649950dba1e411250cd410c18439d6471062 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Mon, 8 Sep 2014 19:32:47 -0400 Subject: [PATCH 2/6] Include alias tests in project --- src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj b/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj index 1d063341b19..1032c68b5da 100644 --- a/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj +++ b/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj @@ -123,6 +123,7 @@ + @@ -134,6 +135,9 @@ Always + + Always + Always From 65cbf58669e24147d9846f6989d85029485f405f Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Mon, 8 Sep 2014 19:33:02 -0400 Subject: [PATCH 3/6] BWC changes for PUT alias --- .../Elasticsearch.Net.csproj | 1 + .../Obsolete/IndicesPutAlias.cs | 130 ++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 src/Elasticsearch.Net/Obsolete/IndicesPutAlias.cs diff --git a/src/Elasticsearch.Net/Elasticsearch.Net.csproj b/src/Elasticsearch.Net/Elasticsearch.Net.csproj index 4bc93eaeab2..b84961da02d 100644 --- a/src/Elasticsearch.Net/Elasticsearch.Net.csproj +++ b/src/Elasticsearch.Net/Elasticsearch.Net.csproj @@ -67,6 +67,7 @@ + diff --git a/src/Elasticsearch.Net/Obsolete/IndicesPutAlias.cs b/src/Elasticsearch.Net/Obsolete/IndicesPutAlias.cs new file mode 100644 index 00000000000..ae656a61b72 --- /dev/null +++ b/src/Elasticsearch.Net/Obsolete/IndicesPutAlias.cs @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Elasticsearch.Net +{ + #pragma warning disable 0618 + using System.Threading.Tasks; + using IndicesPutAliasSelector = Func; + #pragma warning restore 0618 + + [Obsolete("Scheduled to be removed in 2.0, renamed to PutAliasRequestParameters")] + public class IndicesPutAliasRequestParameters : PutAliasRequestParameters { } + + public static class IndicesPutAliasClientExtensions + { + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static ElasticsearchResponse IndicesPutAlias(this IElasticsearchClient client, string index, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAlias(index, name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static Task> IndicesPutAliasAsync(this ElasticsearchClient client, string index, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAliasAsync(index, name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static ElasticsearchResponse IndicesPutAlias(this IElasticsearchClient client, string index, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAlias(index, name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static Task> IndicesPutAliasAsync(this IElasticsearchClient client, string index, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAliasAsync(index, name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static ElasticsearchResponse IndicesPutAliasForAll(this IElasticsearchClient client, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAliasForAll(name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static Task> IndicesPutAliasForAllAsync(this IElasticsearchClient client, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAliasForAllAsync(name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static ElasticsearchResponse IndicesPutAliasForAll(this IElasticsearchClient client, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAliasForAll(name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static Task> IndicesPutAliasForAllAsync(this IElasticsearchClient client, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAliasForAllAsync(name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static ElasticsearchResponse IndicesPutAliasPost(this IElasticsearchClient client, string index, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAliasPost(index, name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static Task> IndicesPutAliasPostAsync(this IElasticsearchClient client, string index, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAliasPostAsync(index, name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static ElasticsearchResponse IndicesPutAliasPost(this IElasticsearchClient client, string index, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAliasPost(index, name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static Task> IndicesPutAliasPostAsync(this IElasticsearchClient client, string index, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAliasPostAsync(index, name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static ElasticsearchResponse IndicesPutAliasPostForAll(this IElasticsearchClient client, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAliasForAll(name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static Task> IndicesPutAliasPostForAllAsync(this IElasticsearchClient client, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAliasForAllAsync(name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static ElasticsearchResponse IndicesPutAliasPostForAll(this IElasticsearchClient client, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAliasForAll(name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of PutAliasRequestParameters")] + public static Task> IndicesPutAliasPostForAllAsync(this IElasticsearchClient client, string name, object body, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesPutAliasForAllAsync(name, selector); + } + } +} From a67dfb8c378bbe1dd85beb98bab7a68daec8f1f4 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Mon, 8 Sep 2014 21:02:56 -0400 Subject: [PATCH 4/6] Add support for the DELETE alias endpoint --- .../RequestParameters.Generated.cs | 6 +-- .../ElasticsearchClient.Generated.cs | 16 ++++---- .../IElasticsearchClient.Generated.cs | 8 ++-- src/Nest/DSL/DeleteAliasDescriptor.cs | 41 +++++++++++++++++++ src/Nest/DSL/_Descriptors.generated.cs | 12 ++---- src/Nest/DSL/_Requests.generated.cs | 8 +--- .../Domain/Responses/DeleteAliasResponse.cs | 15 +++++++ src/Nest/ElasticClient-Aliases.cs | 34 +++++++++++++++ src/Nest/IElasticClient.cs | 8 ++++ src/Nest/Nest.csproj | 2 + src/Nest/RawDispatch.generated.cs | 4 +- .../Indices/AliasTests.cs | 25 +++++++++++ 12 files changed, 146 insertions(+), 33 deletions(-) create mode 100644 src/Nest/DSL/DeleteAliasDescriptor.cs create mode 100644 src/Nest/Domain/Responses/DeleteAliasResponse.cs diff --git a/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs b/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs index fb02913a431..1b8db5cd522 100644 --- a/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs +++ b/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs @@ -2638,12 +2638,12 @@ public DeleteIndexRequestParameters MasterTimeout(string master_timeout) ///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-aliases.html /// /// - public class IndicesDeleteAliasRequestParameters : FluentRequestParameters + public class DeleteAliasRequestParameters : FluentRequestParameters { internal string _timeout { get; set; } ///Explicit timestamp for the document - public IndicesDeleteAliasRequestParameters Timeout(string timeout) + public DeleteAliasRequestParameters Timeout(string timeout) { this._timeout = timeout; this.AddQueryString("timeout", this._timeout); @@ -2653,7 +2653,7 @@ public IndicesDeleteAliasRequestParameters Timeout(string timeout) internal string _master_timeout { get; set; } ///Specify timeout for connection to master - public IndicesDeleteAliasRequestParameters MasterTimeout(string master_timeout) + public DeleteAliasRequestParameters MasterTimeout(string master_timeout) { this._master_timeout = master_timeout; this.AddQueryString("master_timeout", this._master_timeout); diff --git a/src/Elasticsearch.Net/ElasticsearchClient.Generated.cs b/src/Elasticsearch.Net/ElasticsearchClient.Generated.cs index d0591e6562d..3ac6ba9f45e 100644 --- a/src/Elasticsearch.Net/ElasticsearchClient.Generated.cs +++ b/src/Elasticsearch.Net/ElasticsearchClient.Generated.cs @@ -11025,7 +11025,7 @@ public Task> IndicesDeleteAsync(string /// - If T is of type byte[] deserialization will be shortcircuited /// - If T is of type VoidResponse the response stream will be ignored completely /// - public ElasticsearchResponse IndicesDeleteAlias(string index, string name, Func requestParameters = null) + public ElasticsearchResponse IndicesDeleteAlias(string index, string name, Func requestParameters = null) { index.ThrowIfNullOrEmpty("index"); name.ThrowIfNullOrEmpty("name"); @@ -11034,7 +11034,7 @@ public ElasticsearchResponse IndicesDeleteAlias(string index, string name, if (requestParameters != null) { - requestParams = requestParameters(new IndicesDeleteAliasRequestParameters()); + requestParams = requestParameters(new DeleteAliasRequestParameters()); } @@ -11061,7 +11061,7 @@ public ElasticsearchResponse IndicesDeleteAlias(string index, string name, /// - If T is of type byte[] deserialization will be shortcircuited /// - If T is of type VoidResponse the response stream will be ignored completely /// - public Task> IndicesDeleteAliasAsync(string index, string name, Func requestParameters = null) + public Task> IndicesDeleteAliasAsync(string index, string name, Func requestParameters = null) { index.ThrowIfNullOrEmpty("index"); name.ThrowIfNullOrEmpty("name"); @@ -11070,7 +11070,7 @@ public Task> IndicesDeleteAliasAsync(string index, s if (requestParameters != null) { - requestParams = requestParameters(new IndicesDeleteAliasRequestParameters()); + requestParams = requestParameters(new DeleteAliasRequestParameters()); } @@ -11099,7 +11099,7 @@ public Task> IndicesDeleteAliasAsync(string index, s /// - i.e result.Response.hits.hits[0].property.nested["nested_deeper"] /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - public ElasticsearchResponse IndicesDeleteAlias(string index, string name, Func requestParameters = null) + public ElasticsearchResponse IndicesDeleteAlias(string index, string name, Func requestParameters = null) { index.ThrowIfNullOrEmpty("index"); name.ThrowIfNullOrEmpty("name"); @@ -11108,7 +11108,7 @@ public ElasticsearchResponse IndicesDeleteAlias(string index, if (requestParameters != null) { - requestParams = requestParameters(new IndicesDeleteAliasRequestParameters()); + requestParams = requestParameters(new DeleteAliasRequestParameters()); } @@ -11137,7 +11137,7 @@ public ElasticsearchResponse IndicesDeleteAlias(string index, /// - i.e result.Response.hits.hits[0].property.nested["nested_deeper"] /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - public Task> IndicesDeleteAliasAsync(string index, string name, Func requestParameters = null) + public Task> IndicesDeleteAliasAsync(string index, string name, Func requestParameters = null) { index.ThrowIfNullOrEmpty("index"); name.ThrowIfNullOrEmpty("name"); @@ -11146,7 +11146,7 @@ public Task> IndicesDeleteAliasAsync(st if (requestParameters != null) { - requestParams = requestParameters(new IndicesDeleteAliasRequestParameters()); + requestParams = requestParameters(new DeleteAliasRequestParameters()); } diff --git a/src/Elasticsearch.Net/IElasticsearchClient.Generated.cs b/src/Elasticsearch.Net/IElasticsearchClient.Generated.cs index 86ff34f6069..f7bf0a7352f 100644 --- a/src/Elasticsearch.Net/IElasticsearchClient.Generated.cs +++ b/src/Elasticsearch.Net/IElasticsearchClient.Generated.cs @@ -5769,7 +5769,7 @@ public interface IElasticsearchClient /// - If T is of type VoidResponse the response stream will be ignored completely /// - ElasticsearchResponse IndicesDeleteAlias(string index, string name, Func requestParameters = null); + ElasticsearchResponse IndicesDeleteAlias(string index, string name, Func requestParameters = null); ///Represents a DELETE on /{index}/_alias/{name} ///Returns: A task that'll return an ElasticsearchResponse<T> holding the reponse body deserialized as T. @@ -5788,7 +5788,7 @@ public interface IElasticsearchClient /// - If T is of type VoidResponse the response stream will be ignored completely /// - Task> IndicesDeleteAliasAsync(string index, string name, Func requestParameters = null); + Task> IndicesDeleteAliasAsync(string index, string name, Func requestParameters = null); ///Represents a DELETE on /{index}/_alias/{name} ///Returns: ElasticsearchResponse<T> holding the response body deserialized as DynamicDictionary @@ -5809,7 +5809,7 @@ public interface IElasticsearchClient /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - ElasticsearchResponse IndicesDeleteAlias(string index, string name, Func requestParameters = null); + ElasticsearchResponse IndicesDeleteAlias(string index, string name, Func requestParameters = null); ///Represents a DELETE on /{index}/_alias/{name} ///Returns: Task that'll return an ElasticsearchResponse<T$gt; holding the response body deserialized as DynamicDictionary @@ -5830,7 +5830,7 @@ public interface IElasticsearchClient /// - can be safely dispatched to a nullable type even if intermediate properties do not exist /// - Task> IndicesDeleteAliasAsync(string index, string name, Func requestParameters = null); + Task> IndicesDeleteAliasAsync(string index, string name, Func requestParameters = null); ///Represents a DELETE on /{index}/{type}/_mapping ///Returns: ElasticsearchResponse<T> holding the reponse body deserialized as T. diff --git a/src/Nest/DSL/DeleteAliasDescriptor.cs b/src/Nest/DSL/DeleteAliasDescriptor.cs new file mode 100644 index 00000000000..861db5c4a08 --- /dev/null +++ b/src/Nest/DSL/DeleteAliasDescriptor.cs @@ -0,0 +1,41 @@ +using Elasticsearch.Net; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public interface IDeleteAliasRequest : IIndexNamePath + { + } + + internal static class DeleteAliasPathInfo + { + public static void Update(ElasticsearchPathInfo pathInfo) + { + pathInfo.HttpMethod = PathInfoHttpMethod.DELETE; + } + } + + public partial class DeleteAliasRequest : IndexNamePathBase, IDeleteAliasRequest + { + public DeleteAliasRequest(string index, string name) : base(index, name) { } + + protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) + { + DeleteAliasPathInfo.Update(pathInfo); + } + } + + [DescriptorFor("IndicesDeleteAlias")] + public partial class DeleteAliasDescriptor + : IndexNamePathDescriptor, DeleteAliasRequestParameters, T>, IDeleteAliasRequest + where T : class + { + protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) + { + DeleteAliasPathInfo.Update(pathInfo); + } + } +} diff --git a/src/Nest/DSL/_Descriptors.generated.cs b/src/Nest/DSL/_Descriptors.generated.cs index e79fa9ba05e..fa59ead78e6 100644 --- a/src/Nest/DSL/_Descriptors.generated.cs +++ b/src/Nest/DSL/_Descriptors.generated.cs @@ -2443,13 +2443,13 @@ public DeleteIndexDescriptor MasterTimeout(string master_timeout) ///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-aliases.html /// /// - public partial class IndicesDeleteAliasDescriptor : BaseRequest + public partial class DeleteAliasDescriptor { ///Explicit timestamp for the document - public IndicesDeleteAliasDescriptor Timeout(string timeout) + public DeleteAliasDescriptor Timeout(string timeout) { this.Request.RequestParameters.Timeout(timeout); return this; @@ -2457,18 +2457,12 @@ public IndicesDeleteAliasDescriptor Timeout(string timeout) ///Specify timeout for connection to master - public IndicesDeleteAliasDescriptor MasterTimeout(string master_timeout) + public DeleteAliasDescriptor MasterTimeout(string master_timeout) { this.Request.RequestParameters.MasterTimeout(master_timeout); return this; } - - protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) - { - throw new NotImplementedException(); - } - } diff --git a/src/Nest/DSL/_Requests.generated.cs b/src/Nest/DSL/_Requests.generated.cs index ceec210200d..1c807b887e3 100644 --- a/src/Nest/DSL/_Requests.generated.cs +++ b/src/Nest/DSL/_Requests.generated.cs @@ -2212,7 +2212,7 @@ public string MasterTimeout ///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-aliases.html /// /// - public partial class IndicesDeleteAliasRequest : BasePathRequest + public partial class DeleteAliasRequest { ///Explicit timestamp for the document @@ -2230,12 +2230,6 @@ public string MasterTimeout set { this.Request.RequestParameters.AddQueryString("master_timeout", value); } } - - protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) - { - throw new NotImplementedException(); - } - } diff --git a/src/Nest/Domain/Responses/DeleteAliasResponse.cs b/src/Nest/Domain/Responses/DeleteAliasResponse.cs new file mode 100644 index 00000000000..6e1b32de4f9 --- /dev/null +++ b/src/Nest/Domain/Responses/DeleteAliasResponse.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Nest +{ + public interface IDeleteAliasResponse : IResponse + { + } + + public class DeleteAliasResponse : BaseResponse, IDeleteAliasResponse + { + } +} diff --git a/src/Nest/ElasticClient-Aliases.cs b/src/Nest/ElasticClient-Aliases.cs index 62b3f1968b2..1ac3c153498 100644 --- a/src/Nest/ElasticClient-Aliases.cs +++ b/src/Nest/ElasticClient-Aliases.cs @@ -173,6 +173,40 @@ public Task PutAliasAsync(Func( + deleteAliasRequest, + (p, d) => this.RawDispatch.IndicesDeleteAliasDispatch(p) + ); + } + + public Task DeleteAliasAsync(IDeleteAliasRequest deleteAliasRequest) + { + return this.DispatchAsync( + deleteAliasRequest, + (p, d) => this.RawDispatch.IndicesDeleteAliasDispatchAsync(p) + ); + } + + public IDeleteAliasResponse DeleteAlias(Func, DeleteAliasDescriptor> deleteAliasDescriptor) + where T : class + { + return this.Dispatch, DeleteAliasRequestParameters, DeleteAliasResponse>( + deleteAliasDescriptor, + (p, d) => this.RawDispatch.IndicesDeleteAliasDispatch(p) + ); + } + + public Task DeleteAliasAsync(Func, DeleteAliasDescriptor> deleteAliasDescriptor) + where T : class + { + return this.DispatchAsync, DeleteAliasRequestParameters, DeleteAliasResponse, IDeleteAliasResponse>( + deleteAliasDescriptor, + (p, d) => this.RawDispatch.IndicesDeleteAliasDispatchAsync(p) + ); + } + /// private GetAliasesResponse DeserializeGetAliasesResponse(IElasticsearchResponse connectionStatus, Stream stream) { diff --git a/src/Nest/IElasticClient.cs b/src/Nest/IElasticClient.cs index 53c89ca49d7..58108c54d3c 100644 --- a/src/Nest/IElasticClient.cs +++ b/src/Nest/IElasticClient.cs @@ -1016,6 +1016,14 @@ Task> GetAsync(IGetRequest getRequest) Task PutAliasAsync(Func putAliasDescriptor); + IDeleteAliasResponse DeleteAlias(IDeleteAliasRequest deleteAliasRequest); + + Task DeleteAliasAsync(IDeleteAliasRequest deleteAliasRequest); + + IDeleteAliasResponse DeleteAlias(Func, DeleteAliasDescriptor> deleteAliasDescriptor) where T : class; + + Task DeleteAliasAsync(Func, DeleteAliasDescriptor> deleteAliasDescriptor) where T : class; + /// /// The optimize API allows to optimize one or more indices through an API. The optimize process basically optimizes /// the index for faster search operations (and relates to the number of segments a Lucene index holds within each shard). diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index b4ec46ebe0c..f7cc98914b8 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -181,6 +181,7 @@ + @@ -226,6 +227,7 @@ + diff --git a/src/Nest/RawDispatch.generated.cs b/src/Nest/RawDispatch.generated.cs index 2fee993cb1e..dcb667b11c8 100644 --- a/src/Nest/RawDispatch.generated.cs +++ b/src/Nest/RawDispatch.generated.cs @@ -1330,7 +1330,7 @@ internal Task> IndicesDeleteDispatchAsync(Elasticsea } - internal ElasticsearchResponse IndicesDeleteAliasDispatch(ElasticsearchPathInfo pathInfo ) + internal ElasticsearchResponse IndicesDeleteAliasDispatch(ElasticsearchPathInfo pathInfo ) { switch(pathInfo.HttpMethod) { @@ -1345,7 +1345,7 @@ internal ElasticsearchResponse IndicesDeleteAliasDispatch(ElasticsearchPat } - internal Task> IndicesDeleteAliasDispatchAsync(ElasticsearchPathInfo pathInfo ) + internal Task> IndicesDeleteAliasDispatchAsync(ElasticsearchPathInfo pathInfo ) { switch(pathInfo.HttpMethod) { diff --git a/src/Tests/Nest.Tests.Integration/Indices/AliasTests.cs b/src/Tests/Nest.Tests.Integration/Indices/AliasTests.cs index 165782a35a6..2289039b4ce 100644 --- a/src/Tests/Nest.Tests.Integration/Indices/AliasTests.cs +++ b/src/Tests/Nest.Tests.Integration/Indices/AliasTests.cs @@ -299,5 +299,30 @@ public void PutSingleAlias() alias.Filter.Term.Field.Should().Be("name"); alias.Filter.Term.Value.Should().Be("nest"); } + + [Test] + public void DeleteSingleAlias() + { + var indexName = ElasticsearchConfiguration.NewUniqueIndexName(); + var aliasName = ElasticsearchConfiguration.NewUniqueIndexName(); + + var createIndexResponse = this.Client.CreateIndex(indexName); + createIndexResponse.IsValid.Should().BeTrue(); + + var putAliasResponse = this.Client.PutAlias(a => a + .Index(indexName) + .Name(aliasName) + ); + putAliasResponse.IsValid.Should().BeTrue(); + + var aliases = this.Client.GetAliasesPointingToIndex(indexName); + aliases.Should().NotBeNull().And.HaveCount(1); + + var deleteAliasResponse = this.Client.DeleteAlias(new DeleteAliasRequest(indexName, aliasName)); + deleteAliasResponse.IsValid.Should().BeTrue(); + + aliases = this.Client.GetAliasesPointingToIndex(indexName); + aliases.Should().NotBeNull().And.HaveCount(0); + } } } \ No newline at end of file From f681b63c4a01f3bb6a38da464b94243804cead86 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Mon, 8 Sep 2014 21:17:45 -0400 Subject: [PATCH 5/6] BWC changes for DELETE alias --- .../Elasticsearch.Net.csproj | 1 + .../Obsolete/IndicesDeleteAlias.cs | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/Elasticsearch.Net/Obsolete/IndicesDeleteAlias.cs diff --git a/src/Elasticsearch.Net/Elasticsearch.Net.csproj b/src/Elasticsearch.Net/Elasticsearch.Net.csproj index b84961da02d..e5b3e6aa6e6 100644 --- a/src/Elasticsearch.Net/Elasticsearch.Net.csproj +++ b/src/Elasticsearch.Net/Elasticsearch.Net.csproj @@ -67,6 +67,7 @@ + diff --git a/src/Elasticsearch.Net/Obsolete/IndicesDeleteAlias.cs b/src/Elasticsearch.Net/Obsolete/IndicesDeleteAlias.cs new file mode 100644 index 00000000000..1baa7a2b42c --- /dev/null +++ b/src/Elasticsearch.Net/Obsolete/IndicesDeleteAlias.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Elasticsearch.Net +{ + #pragma warning disable 0618 + using System.Threading.Tasks; + using IndicesDeleteAliasSelector = Func; + #pragma warning restore 0618 + + [Obsolete("Scheduled to be removed in 2.0, renamed to DeleteAliasRequestParameters")] + public class IndicesDeleteAliasRequestParameters : DeleteAliasRequestParameters { } + + public static class IndicesDeleteAliasClientExtensions + { + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of DeleteAliasRequestParameters")] + public static ElasticsearchResponse IndicesDeleteAlias(this IElasticsearchClient client, string index, string name, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesDeleteAlias(index, name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of DeleteAliasRequestParameters")] + public static Task> IndicesDeleteAliasAsync(this IElasticsearchClient client, string index, string name, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesDeleteAliasAsync(index, name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of DeleteAliasRequestParameters")] + public static ElasticsearchResponse IndicesDeleteAlias(this IElasticsearchClient client, string index, string name, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesDeleteAlias(index, name, selector); + } + + [Obsolete("Scheduled to be removed in 2.0, use the method that takes a Func of DeleteAliasRequestParameters")] + public static Task> IndicesDeleteAliasAsync(this IElasticsearchClient client, string index, string name, Func requestParameters = null) + { + var selector = Obsolete.UpCastSelector(requestParameters); + return client.IndicesDeleteAliasAsync(index, name, selector); + } + } +} From 0d9e65fb3a82e6c73f5574419a9fff3a2ffb277f Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Mon, 8 Sep 2014 21:28:24 -0400 Subject: [PATCH 6/6] XML docs for alias methods --- src/Nest/ElasticClient-Aliases.cs | 4 ++++ src/Nest/IElasticClient.cs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Nest/ElasticClient-Aliases.cs b/src/Nest/ElasticClient-Aliases.cs index 1ac3c153498..9ae8af7ecbd 100644 --- a/src/Nest/ElasticClient-Aliases.cs +++ b/src/Nest/ElasticClient-Aliases.cs @@ -173,6 +173,7 @@ public Task PutAliasAsync(Func public IDeleteAliasResponse DeleteAlias(IDeleteAliasRequest deleteAliasRequest) { return this.Dispatch( @@ -181,6 +182,7 @@ public IDeleteAliasResponse DeleteAlias(IDeleteAliasRequest deleteAliasRequest) ); } + /// public Task DeleteAliasAsync(IDeleteAliasRequest deleteAliasRequest) { return this.DispatchAsync( @@ -189,6 +191,7 @@ public Task DeleteAliasAsync(IDeleteAliasRequest deleteAli ); } + /// public IDeleteAliasResponse DeleteAlias(Func, DeleteAliasDescriptor> deleteAliasDescriptor) where T : class { @@ -198,6 +201,7 @@ public IDeleteAliasResponse DeleteAlias(Func, Delete ); } + /// public Task DeleteAliasAsync(Func, DeleteAliasDescriptor> deleteAliasDescriptor) where T : class { diff --git a/src/Nest/IElasticClient.cs b/src/Nest/IElasticClient.cs index 58108c54d3c..7e110887dbb 100644 --- a/src/Nest/IElasticClient.cs +++ b/src/Nest/IElasticClient.cs @@ -1008,20 +1008,36 @@ Task> GetAsync(IGetRequest getRequest) /// Task GetAliasesAsync(IGetAliasesRequest getAliasesRequest); + /// + /// Add a single index alias + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html#alias-adding + /// + /// A descriptor that describes the put alias request IPutAliasResponse PutAlias(IPutAliasRequest putAliasRequest); + /// Task PutAliasAsync(IPutAliasRequest putAliasRequest); + /// IPutAliasResponse PutAlias(Func putAliasDescriptor); + /// Task PutAliasAsync(Func putAliasDescriptor); + /// + /// Delete an index alias + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html#deleting + /// + /// A descriptor that describes the delete alias request IDeleteAliasResponse DeleteAlias(IDeleteAliasRequest deleteAliasRequest); + /// Task DeleteAliasAsync(IDeleteAliasRequest deleteAliasRequest); + /// IDeleteAliasResponse DeleteAlias(Func, DeleteAliasDescriptor> deleteAliasDescriptor) where T : class; + /// Task DeleteAliasAsync(Func, DeleteAliasDescriptor> deleteAliasDescriptor) where T : class; ///