From 5449d7ecf43bf5efe62048d4e93b4c19915f016a Mon Sep 17 00:00:00 2001 From: Mpdreamz Date: Mon, 13 Aug 2018 13:30:15 +0200 Subject: [PATCH 1/4] Generate ExcecutePainlessScript methods/descriptors etc --- .../ApiGenerator/ApiGenerator.cs | 2 - .../RequestParameters.Generated.cs | 5 ++ .../ElasticLowLevelClient.Generated.cs | 18 ++++++++ .../IElasticLowLevelClient.Generated.cs | 14 ++++++ .../ElasticClient-ExecutePainlessScript.cs | 46 +++++++++++++++++++ .../ExecutePainlessScriptRequest.cs | 27 +++++++++++ .../ExecutePainlessScriptResponse.cs | 6 +++ src/Nest/_Generated/_Descriptors.generated.cs | 8 ++++ .../_Generated/_LowLevelDispatch.generated.cs | 24 ++++++++++ src/Nest/_Generated/_Requests.generated.cs | 12 +++++ 10 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs create mode 100644 src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptRequest.cs create mode 100644 src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptResponse.cs diff --git a/src/CodeGeneration/ApiGenerator/ApiGenerator.cs b/src/CodeGeneration/ApiGenerator/ApiGenerator.cs index 44e0842d4ba..0a2ff7d1349 100644 --- a/src/CodeGeneration/ApiGenerator/ApiGenerator.cs +++ b/src/CodeGeneration/ApiGenerator/ApiGenerator.cs @@ -84,8 +84,6 @@ public static void Generate(string downloadBranch, params string[] folders) "xpack.sql.query.json", "xpack.sql.translate.json", "xpack.ssl.certificates.json", - - "scripts_painless_execute.json", }; private static RestApiSpec CreateRestApiSpecModel(string downloadBranch, string[] folders) diff --git a/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs b/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs index cde78595e10..9efe394d6d8 100644 --- a/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs +++ b/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs @@ -1751,6 +1751,11 @@ public partial class RenderSearchTemplateRequestParameters : RequestParameters HttpMethod.POST; } + ///Request options for ScriptsPainlessExecute
https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html
+ public partial class ExecutePainlessScriptRequestParameters : RequestParameters + { + public override HttpMethod DefaultHttpMethod => HttpMethod.POST; + } ///Request options for Scroll
http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html
public partial class ScrollRequestParameters : RequestParameters { diff --git a/src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs b/src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs index 4aaa7eb7f6d..a7cbbdc61d2 100644 --- a/src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs +++ b/src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs @@ -2416,6 +2416,24 @@ public TResponse RenderSearchTemplate(string id, PostData body, Rende ///A func that allows you to describe the querystring parameters & request specific connection settings. public Task RenderSearchTemplateAsync(string id, PostData body, RenderSearchTemplateRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync(POST, Url($"_render/template/{id.NotNull("id")}"), ctx, body, _params(requestParameters)); + ///GET on /_scripts/painless/_execute https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html + ///A func that allows you to describe the querystring parameters & request specific connection settings. + public TResponse ScriptsPainlessExecuteGet(ExecutePainlessScriptRequestParameters requestParameters = null) + where TResponse : class, IElasticsearchResponse, new() => this.DoRequest(GET, Url($"_scripts/painless/_execute"), null, _params(requestParameters)); + ///GET on /_scripts/painless/_execute https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html + ///A func that allows you to describe the querystring parameters & request specific connection settings. + public Task ScriptsPainlessExecuteGetAsync(ExecutePainlessScriptRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) + where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync(GET, Url($"_scripts/painless/_execute"), ctx, null, _params(requestParameters)); + ///POST on /_scripts/painless/_execute https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html + ///The script to execute + ///A func that allows you to describe the querystring parameters & request specific connection settings. + public TResponse ScriptsPainlessExecute(PostData body, ExecutePainlessScriptRequestParameters requestParameters = null) + where TResponse : class, IElasticsearchResponse, new() => this.DoRequest(POST, Url($"_scripts/painless/_execute"), body, _params(requestParameters)); + ///POST on /_scripts/painless/_execute https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html + ///The script to execute + ///A func that allows you to describe the querystring parameters & request specific connection settings. + public Task ScriptsPainlessExecuteAsync(PostData body, ExecutePainlessScriptRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) + where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync(POST, Url($"_scripts/painless/_execute"), ctx, body, _params(requestParameters)); ///GET on /_search/scroll http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html ///A func that allows you to describe the querystring parameters & request specific connection settings. public TResponse ScrollGet(ScrollRequestParameters requestParameters = null) diff --git a/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs b/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs index 354ab3df777..577288ec335 100644 --- a/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs +++ b/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs @@ -1956,6 +1956,20 @@ public partial interface IElasticLowLevelClient ///The search definition template and its params ///A func that allows you to describe the querystring parameters & request specific connection settings. Task RenderSearchTemplateAsync(string id, PostData body, RenderSearchTemplateRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new(); + ///GET on /_scripts/painless/_execute https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html + ///A func that allows you to describe the querystring parameters & request specific connection settings. + TResponse ScriptsPainlessExecuteGet(ExecutePainlessScriptRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new(); + ///GET on /_scripts/painless/_execute https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html + ///A func that allows you to describe the querystring parameters & request specific connection settings. + Task ScriptsPainlessExecuteGetAsync(ExecutePainlessScriptRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new(); + ///POST on /_scripts/painless/_execute https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html + ///The script to execute + ///A func that allows you to describe the querystring parameters & request specific connection settings. + TResponse ScriptsPainlessExecute(PostData body, ExecutePainlessScriptRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new(); + ///POST on /_scripts/painless/_execute https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html + ///The script to execute + ///A func that allows you to describe the querystring parameters & request specific connection settings. + Task ScriptsPainlessExecuteAsync(PostData body, ExecutePainlessScriptRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new(); ///GET on /_search/scroll http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html ///A func that allows you to describe the querystring parameters & request specific connection settings. TResponse ScrollGet(ScrollRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new(); diff --git a/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs b/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs new file mode 100644 index 00000000000..7e975f1f2f8 --- /dev/null +++ b/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs @@ -0,0 +1,46 @@ +using System; +using System.Threading.Tasks; +using Elasticsearch.Net; +using System.Threading; + +namespace Nest +{ + public partial interface IElasticClient + { + /// + IExecutePainlessScriptResponse ExecutePainlessScript(string source, Func selector = null); + + /// + IExecutePainlessScriptResponse ExecutePainlessScript(IExecutePainlessScriptRequest request); + + /// + Task ExecutePainlessScriptAsync(string source, Func selector = null, + CancellationToken cancellationToken = default(CancellationToken)); + + /// + Task ExecutePainlessScriptAsync(IExecutePainlessScriptRequest request, CancellationToken cancellationToken = default(CancellationToken)); + + } + public partial class ElasticClient + { + public IExecutePainlessScriptResponse ExecutePainlessScript(string source, Func selector = null) => + this.ExecutePainlessScript(selector?.Invoke(new ExecutePainlessScriptDescriptor().Painless(source))); + + public IExecutePainlessScriptResponse ExecutePainlessScript(IExecutePainlessScriptRequest request) => + this.Dispatcher.Dispatch( + request, + this.LowLevelDispatch.ScriptsPainlessExecuteDispatch + ); + + public Task ExecutePainlessScriptAsync(string source, Func selector = null, + CancellationToken cancellationToken = default(CancellationToken)) => + this.ExecutePainlessScriptAsync(selector?.Invoke(new ExecutePainlessScriptDescriptor().Painless(source)), cancellationToken); + + public Task ExecutePainlessScriptAsync(IExecutePainlessScriptRequest request, CancellationToken cancellationToken = default(CancellationToken)) => + this.Dispatcher.DispatchAsync( + request, + cancellationToken, + this.LowLevelDispatch.ScriptsPainlessExecuteDispatchAsync + ); + } +} diff --git a/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptRequest.cs b/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptRequest.cs new file mode 100644 index 00000000000..a0738dd62c3 --- /dev/null +++ b/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptRequest.cs @@ -0,0 +1,27 @@ +using System; +using Newtonsoft.Json; + +namespace Nest +{ + public partial interface IExecutePainlessScriptRequest + { + [JsonProperty("script")] + PainlessScript Script { get; set; } + } + + public partial class ExecutePainlessScriptRequest + { + public PainlessScript Script { get; set; } + } + + [DescriptorFor("ScriptsPainlessExecute")] + public partial class ExecutePainlessScriptDescriptor + { + PainlessScript IExecutePainlessScriptRequest.Script { get; set; } + + /// + /// A Painless language script + /// + public ExecutePainlessScriptDescriptor Painless(string source) => Assign(a => a.Script = new PainlessScript(source)); + } +} diff --git a/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptResponse.cs b/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptResponse.cs new file mode 100644 index 00000000000..21c4f9d4f54 --- /dev/null +++ b/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptResponse.cs @@ -0,0 +1,6 @@ +namespace Nest +{ + public interface IExecutePainlessScriptResponse : IResponse { } + + public class ExecutePainlessScriptResponse : ResponseBase, IExecutePainlessScriptResponse { } +} diff --git a/src/Nest/_Generated/_Descriptors.generated.cs b/src/Nest/_Generated/_Descriptors.generated.cs index 509aa2e9ee0..ba837c6bf11 100644 --- a/src/Nest/_Generated/_Descriptors.generated.cs +++ b/src/Nest/_Generated/_Descriptors.generated.cs @@ -3124,6 +3124,14 @@ public RenderSearchTemplateDescriptor() : base(){} // Request parameters + } + ///descriptor for ScriptsPainlessExecute
https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html
+ public partial class ExecutePainlessScriptDescriptor : RequestDescriptorBase, IExecutePainlessScriptRequest + { + // values part of the url path + + // Request parameters + } ///descriptor for Scroll
http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html
public partial class ScrollDescriptor : RequestDescriptorBase,ScrollRequestParameters, IScrollRequest>, IScrollRequest diff --git a/src/Nest/_Generated/_LowLevelDispatch.generated.cs b/src/Nest/_Generated/_LowLevelDispatch.generated.cs index 7085ce45018..609af3e7ac8 100644 --- a/src/Nest/_Generated/_LowLevelDispatch.generated.cs +++ b/src/Nest/_Generated/_LowLevelDispatch.generated.cs @@ -2408,6 +2408,30 @@ internal partial class LowLevelDispatch throw InvalidDispatch("RenderSearchTemplate", p, new [] { GET, POST }, "/_render/template", "/_render/template/{id}"); } + internal TResponse ScriptsPainlessExecuteDispatch(IRequest p,SerializableData body) where TResponse : class, IElasticsearchResponse, new() + { + switch(p.HttpMethod) + { + case GET: + return _lowLevel.ScriptsPainlessExecuteGet(p.RequestParameters); + case POST: + return _lowLevel.ScriptsPainlessExecute(body,p.RequestParameters); + } + throw InvalidDispatch("ScriptsPainlessExecute", p, new [] { GET, POST }, "/_scripts/painless/_execute"); + } + + internal Task ScriptsPainlessExecuteDispatchAsync(IRequest p,SerializableData body, CancellationToken ct) where TResponse : class, IElasticsearchResponse, new() + { + switch(p.HttpMethod) + { + case GET: + return _lowLevel.ScriptsPainlessExecuteGetAsync(p.RequestParameters,ct); + case POST: + return _lowLevel.ScriptsPainlessExecuteAsync(body,p.RequestParameters,ct); + } + throw InvalidDispatch("ScriptsPainlessExecute", p, new [] { GET, POST }, "/_scripts/painless/_execute"); + } + internal TResponse ScrollDispatch(IRequest p,SerializableData body) where TResponse : class, IElasticsearchResponse, new() { switch(p.HttpMethod) diff --git a/src/Nest/_Generated/_Requests.generated.cs b/src/Nest/_Generated/_Requests.generated.cs index dd491cfdd77..9f8795da7f8 100644 --- a/src/Nest/_Generated/_Requests.generated.cs +++ b/src/Nest/_Generated/_Requests.generated.cs @@ -2246,6 +2246,18 @@ public EnableUserRequest(Name username) : base(r=>r.Optional("username", usernam public Refresh? Refresh { get => Q("refresh"); set => Q("refresh", value); } } [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public partial interface IExecutePainlessScriptRequest : IRequest + { + } + ///Request parameters for ScriptsPainlessExecute
https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html
+ public partial class ExecutePainlessScriptRequest : PlainRequestBase, IExecutePainlessScriptRequest + { + protected IExecutePainlessScriptRequest Self => this; + // values part of the url path + + // Request parameters + } + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] public partial interface IExecuteWatchRequest : IRequest { Id Id { get; } From b8d48ceb8caba34f7a5920cbbb0ca33c1747259d Mon Sep 17 00:00:00 2001 From: Mpdreamz Date: Mon, 13 Aug 2018 14:25:09 +0200 Subject: [PATCH 2/4] Implement ExecutePainlessScript API with tests Omitting `context` for now since that only takes a single option now which is also the default. Waiting for the API to crystalize here. --- .../ElasticClient-ExecutePainlessScript.cs | 12 ++-- .../ExecutePainlessScriptRequest.cs | 12 ++-- .../ExecutePainlessScriptResponse.cs | 15 +++- .../ExecutePainlessScriptApiTests.cs | 72 +++++++++++++++++++ .../ExecutePainlessScriptUrlTests.cs | 27 +++++++ 5 files changed, 122 insertions(+), 16 deletions(-) create mode 100644 src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptApiTests.cs create mode 100644 src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptUrlTests.cs diff --git a/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs b/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs index 7e975f1f2f8..fa8ed982f3a 100644 --- a/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs +++ b/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs @@ -8,13 +8,13 @@ namespace Nest public partial interface IElasticClient { /// - IExecutePainlessScriptResponse ExecutePainlessScript(string source, Func selector = null); + IExecutePainlessScriptResponse ExecutePainlessScript(Func selector); /// IExecutePainlessScriptResponse ExecutePainlessScript(IExecutePainlessScriptRequest request); /// - Task ExecutePainlessScriptAsync(string source, Func selector = null, + Task ExecutePainlessScriptAsync(Func selector, CancellationToken cancellationToken = default(CancellationToken)); /// @@ -23,8 +23,8 @@ Task ExecutePainlessScriptAsync(string source, F } public partial class ElasticClient { - public IExecutePainlessScriptResponse ExecutePainlessScript(string source, Func selector = null) => - this.ExecutePainlessScript(selector?.Invoke(new ExecutePainlessScriptDescriptor().Painless(source))); + public IExecutePainlessScriptResponse ExecutePainlessScript(Func selector) => + this.ExecutePainlessScript(selector?.Invoke(new ExecutePainlessScriptDescriptor())); public IExecutePainlessScriptResponse ExecutePainlessScript(IExecutePainlessScriptRequest request) => this.Dispatcher.Dispatch( @@ -32,9 +32,9 @@ public IExecutePainlessScriptResponse ExecutePainlessScript(IExecutePainlessScri this.LowLevelDispatch.ScriptsPainlessExecuteDispatch ); - public Task ExecutePainlessScriptAsync(string source, Func selector = null, + public Task ExecutePainlessScriptAsync(Func selector, CancellationToken cancellationToken = default(CancellationToken)) => - this.ExecutePainlessScriptAsync(selector?.Invoke(new ExecutePainlessScriptDescriptor().Painless(source)), cancellationToken); + this.ExecutePainlessScriptAsync(selector?.Invoke(new ExecutePainlessScriptDescriptor()), cancellationToken); public Task ExecutePainlessScriptAsync(IExecutePainlessScriptRequest request, CancellationToken cancellationToken = default(CancellationToken)) => this.Dispatcher.DispatchAsync( diff --git a/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptRequest.cs b/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptRequest.cs index a0738dd62c3..c9bf286cdb6 100644 --- a/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptRequest.cs +++ b/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptRequest.cs @@ -6,22 +6,20 @@ namespace Nest public partial interface IExecutePainlessScriptRequest { [JsonProperty("script")] - PainlessScript Script { get; set; } + IInlineScript Script { get; set; } } public partial class ExecutePainlessScriptRequest { - public PainlessScript Script { get; set; } + public IInlineScript Script { get; set; } } [DescriptorFor("ScriptsPainlessExecute")] public partial class ExecutePainlessScriptDescriptor { - PainlessScript IExecutePainlessScriptRequest.Script { get; set; } + IInlineScript IExecutePainlessScriptRequest.Script { get; set; } - /// - /// A Painless language script - /// - public ExecutePainlessScriptDescriptor Painless(string source) => Assign(a => a.Script = new PainlessScript(source)); + public ExecutePainlessScriptDescriptor Script(Func selector) => + Assign(a => a.Script = selector?.Invoke(new InlineScriptDescriptor())); } } diff --git a/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptResponse.cs b/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptResponse.cs index 21c4f9d4f54..d09a25e0184 100644 --- a/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptResponse.cs +++ b/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptResponse.cs @@ -1,6 +1,15 @@ -namespace Nest +using Newtonsoft.Json; + +namespace Nest { - public interface IExecutePainlessScriptResponse : IResponse { } + public interface IExecutePainlessScriptResponse : IResponse + { + [JsonProperty("result")] + string Result { get; } + } - public class ExecutePainlessScriptResponse : ResponseBase, IExecutePainlessScriptResponse { } + public class ExecutePainlessScriptResponse : ResponseBase, IExecutePainlessScriptResponse + { + public string Result { get; set; } + } } diff --git a/src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptApiTests.cs b/src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptApiTests.cs new file mode 100644 index 00000000000..f433a7bec11 --- /dev/null +++ b/src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptApiTests.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Elastic.Xunit.XunitPlumbing; +using Elasticsearch.Net; +using FluentAssertions; +using Nest; +using Tests.Core.Extensions; +using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Framework; +using Tests.Framework.Integration; +using Tests.Framework.ManagedElasticsearch.Clusters; +using Xunit; + +namespace Tests.Modules.Scripting.ExecutePainlessScript +{ + [SkipVersion("<6.3.0", "this API was introduced in 6.3.0")] + public class ExecutePainlessScriptApiTests + : ApiIntegrationTestBase + { + public ExecutePainlessScriptApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + + private static readonly string _painlessScript = "params.count / params.total"; + + protected override LazyResponses ClientUsage() => Calls( + fluent: (client, f) => client.ExecutePainlessScript(f), + fluentAsync: (client, f) => client.ExecutePainlessScriptAsync(f), + request: (client, r) => client.ExecutePainlessScript(r), + requestAsync: (client, r) => client.ExecutePainlessScriptAsync(r) + ); + + protected override HttpMethod HttpMethod => HttpMethod.POST; + protected override string UrlPath => "/_scripts/painless/_execute"; + protected override int ExpectStatusCode => 200; + protected override bool ExpectIsValid => true; + + protected override bool SupportsDeserialization => false; + + protected override object ExpectJson => new + { + script = new + { + source = _painlessScript, + @params = new { count = 100.0, total = 1000.0 } + }, + }; + + protected override Func Fluent => d => d + .Script(s=>s + .Source(_painlessScript) + .Params(p => p.Add("count", 100.0).Add("total", 1000.0)) + ); + + protected override ExecutePainlessScriptRequest Initializer => new ExecutePainlessScriptRequest + { + Script = new InlineScript(_painlessScript) + { + Params = new Dictionary + { + { "count", 100.0 }, + { "total", 1000.0 }, + } + } + }; + + protected override void ExpectResponse(IExecutePainlessScriptResponse response) + { + response.ShouldBeValid(); + response.Result.Should().NotBeNullOrWhiteSpace(); + } + } +} diff --git a/src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptUrlTests.cs b/src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptUrlTests.cs new file mode 100644 index 00000000000..10b24fb06cd --- /dev/null +++ b/src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptUrlTests.cs @@ -0,0 +1,27 @@ +using System.Threading.Tasks; +using Elastic.Xunit.XunitPlumbing; +using Nest; +using Tests.Framework; +using static Tests.Framework.UrlTester; + +namespace Tests.Modules.Scripting.ExecutePainlessScript +{ + public class ExecutePainlessScriptUrlTests + { + [U] public async Task Urls() + { + var painless = "1 + 1"; + var request = new ExecutePainlessScriptRequest + { + Script = new InlineScript(painless) + }; + + await POST("/_scripts/painless/_execute") + .Fluent(c => c.ExecutePainlessScript(f => f.Script(s => s.Source(painless)))) + .Request(c => c.ExecutePainlessScript(request)) + .FluentAsync(c => c.ExecutePainlessScriptAsync(f => f.Script(s => s.Source(painless)))) + .RequestAsync(c => c.ExecutePainlessScriptAsync(request)) + ; + } + } +} From 5545c78ee4bbb98da47543d40d781fd56735584f Mon Sep 17 00:00:00 2001 From: Mpdreamz Date: Mon, 13 Aug 2018 19:29:07 +0200 Subject: [PATCH 3/4] make Result generic in preperation for 6.4 --- .../ElasticClient-ExecutePainlessScript.cs | 28 +++++++++---------- .../ExecutePainlessScriptResponse.cs | 8 +++--- .../ExecutePainlessScriptApiTests.cs | 12 ++++---- .../ExecutePainlessScriptUrlTests.cs | 8 +++--- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs b/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs index fa8ed982f3a..1f895a4d49e 100644 --- a/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs +++ b/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs @@ -8,39 +8,39 @@ namespace Nest public partial interface IElasticClient { /// - IExecutePainlessScriptResponse ExecutePainlessScript(Func selector); + IExecutePainlessScriptResponse ExecutePainlessScript(Func selector); /// - IExecutePainlessScriptResponse ExecutePainlessScript(IExecutePainlessScriptRequest request); + IExecutePainlessScriptResponse ExecutePainlessScript(IExecutePainlessScriptRequest request); /// - Task ExecutePainlessScriptAsync(Func selector, + Task> ExecutePainlessScriptAsync(Func selector, CancellationToken cancellationToken = default(CancellationToken)); /// - Task ExecutePainlessScriptAsync(IExecutePainlessScriptRequest request, CancellationToken cancellationToken = default(CancellationToken)); + Task> ExecutePainlessScriptAsync(IExecutePainlessScriptRequest request, CancellationToken cancellationToken = default(CancellationToken)); } public partial class ElasticClient { - public IExecutePainlessScriptResponse ExecutePainlessScript(Func selector) => - this.ExecutePainlessScript(selector?.Invoke(new ExecutePainlessScriptDescriptor())); + public IExecutePainlessScriptResponse ExecutePainlessScript(Func selector) => + this.ExecutePainlessScript(selector?.Invoke(new ExecutePainlessScriptDescriptor())); - public IExecutePainlessScriptResponse ExecutePainlessScript(IExecutePainlessScriptRequest request) => - this.Dispatcher.Dispatch( + public IExecutePainlessScriptResponse ExecutePainlessScript(IExecutePainlessScriptRequest request) => + this.Dispatcher.Dispatch>( request, - this.LowLevelDispatch.ScriptsPainlessExecuteDispatch + this.LowLevelDispatch.ScriptsPainlessExecuteDispatch> ); - public Task ExecutePainlessScriptAsync(Func selector, + public Task> ExecutePainlessScriptAsync(Func selector, CancellationToken cancellationToken = default(CancellationToken)) => - this.ExecutePainlessScriptAsync(selector?.Invoke(new ExecutePainlessScriptDescriptor()), cancellationToken); + this.ExecutePainlessScriptAsync(selector?.Invoke(new ExecutePainlessScriptDescriptor()), cancellationToken); - public Task ExecutePainlessScriptAsync(IExecutePainlessScriptRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + public Task> ExecutePainlessScriptAsync(IExecutePainlessScriptRequest request, CancellationToken cancellationToken = default(CancellationToken)) => + this.Dispatcher.DispatchAsync, IExecutePainlessScriptResponse>( request, cancellationToken, - this.LowLevelDispatch.ScriptsPainlessExecuteDispatchAsync + this.LowLevelDispatch.ScriptsPainlessExecuteDispatchAsync> ); } } diff --git a/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptResponse.cs b/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptResponse.cs index d09a25e0184..d14936015d0 100644 --- a/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptResponse.cs +++ b/src/Nest/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptResponse.cs @@ -2,14 +2,14 @@ namespace Nest { - public interface IExecutePainlessScriptResponse : IResponse + public interface IExecutePainlessScriptResponse : IResponse { [JsonProperty("result")] - string Result { get; } + TResult Result { get; } } - public class ExecutePainlessScriptResponse : ResponseBase, IExecutePainlessScriptResponse + public class ExecutePainlessScriptResponse : ResponseBase, IExecutePainlessScriptResponse { - public string Result { get; set; } + public TResult Result { get; set; } } } diff --git a/src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptApiTests.cs b/src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptApiTests.cs index f433a7bec11..31b4447e729 100644 --- a/src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptApiTests.cs +++ b/src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptApiTests.cs @@ -16,17 +16,17 @@ namespace Tests.Modules.Scripting.ExecutePainlessScript { [SkipVersion("<6.3.0", "this API was introduced in 6.3.0")] public class ExecutePainlessScriptApiTests - : ApiIntegrationTestBase + : ApiIntegrationTestBase, IExecutePainlessScriptRequest, ExecutePainlessScriptDescriptor, ExecutePainlessScriptRequest> { public ExecutePainlessScriptApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { } private static readonly string _painlessScript = "params.count / params.total"; protected override LazyResponses ClientUsage() => Calls( - fluent: (client, f) => client.ExecutePainlessScript(f), - fluentAsync: (client, f) => client.ExecutePainlessScriptAsync(f), - request: (client, r) => client.ExecutePainlessScript(r), - requestAsync: (client, r) => client.ExecutePainlessScriptAsync(r) + fluent: (client, f) => client.ExecutePainlessScript(f), + fluentAsync: (client, f) => client.ExecutePainlessScriptAsync(f), + request: (client, r) => client.ExecutePainlessScript(r), + requestAsync: (client, r) => client.ExecutePainlessScriptAsync(r) ); protected override HttpMethod HttpMethod => HttpMethod.POST; @@ -63,7 +63,7 @@ protected override LazyResponses ClientUsage() => Calls( } }; - protected override void ExpectResponse(IExecutePainlessScriptResponse response) + protected override void ExpectResponse(IExecutePainlessScriptResponse response) { response.ShouldBeValid(); response.Result.Should().NotBeNullOrWhiteSpace(); diff --git a/src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptUrlTests.cs b/src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptUrlTests.cs index 10b24fb06cd..18b364b1356 100644 --- a/src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptUrlTests.cs +++ b/src/Tests/Tests/Modules/Scripting/ExecutePainlessScript/ExecutePainlessScriptUrlTests.cs @@ -17,10 +17,10 @@ [U] public async Task Urls() }; await POST("/_scripts/painless/_execute") - .Fluent(c => c.ExecutePainlessScript(f => f.Script(s => s.Source(painless)))) - .Request(c => c.ExecutePainlessScript(request)) - .FluentAsync(c => c.ExecutePainlessScriptAsync(f => f.Script(s => s.Source(painless)))) - .RequestAsync(c => c.ExecutePainlessScriptAsync(request)) + .Fluent(c => c.ExecutePainlessScript(f => f.Script(s => s.Source(painless)))) + .Request(c => c.ExecutePainlessScript(request)) + .FluentAsync(c => c.ExecutePainlessScriptAsync(f => f.Script(s => s.Source(painless)))) + .RequestAsync(c => c.ExecutePainlessScriptAsync(request)) ; } } From cbda09aea1061afeb94c0a00132db5b15c72cc63 Mon Sep 17 00:00:00 2001 From: Russ Cam Date: Mon, 20 Aug 2018 15:42:21 +1000 Subject: [PATCH 4/4] Add XML comments --- .../ElasticClient-ExecutePainlessScript.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs b/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs index 1f895a4d49e..f37d57783d1 100644 --- a/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs +++ b/src/Nest/Modules/Scripting/ExecutePainlessScript/ElasticClient-ExecutePainlessScript.cs @@ -7,35 +7,43 @@ namespace Nest { public partial interface IElasticClient { - /// + /// + /// Executes an arbitrary Painless script and returns a result. + /// Useful for testing the syntactical correctness of Painless scripts + /// IExecutePainlessScriptResponse ExecutePainlessScript(Func selector); - /// + /// IExecutePainlessScriptResponse ExecutePainlessScript(IExecutePainlessScriptRequest request); - /// + /// Task> ExecutePainlessScriptAsync(Func selector, CancellationToken cancellationToken = default(CancellationToken)); - /// + /// Task> ExecutePainlessScriptAsync(IExecutePainlessScriptRequest request, CancellationToken cancellationToken = default(CancellationToken)); } + public partial class ElasticClient { + /// public IExecutePainlessScriptResponse ExecutePainlessScript(Func selector) => this.ExecutePainlessScript(selector?.Invoke(new ExecutePainlessScriptDescriptor())); + /// public IExecutePainlessScriptResponse ExecutePainlessScript(IExecutePainlessScriptRequest request) => this.Dispatcher.Dispatch>( request, this.LowLevelDispatch.ScriptsPainlessExecuteDispatch> ); + /// public Task> ExecutePainlessScriptAsync(Func selector, CancellationToken cancellationToken = default(CancellationToken)) => this.ExecutePainlessScriptAsync(selector?.Invoke(new ExecutePainlessScriptDescriptor()), cancellationToken); + /// public Task> ExecutePainlessScriptAsync(IExecutePainlessScriptRequest request, CancellationToken cancellationToken = default(CancellationToken)) => this.Dispatcher.DispatchAsync, IExecutePainlessScriptResponse>( request,