diff --git a/src/CodeGeneration/ApiGenerator/ApiGenerator.cs b/src/CodeGeneration/ApiGenerator/ApiGenerator.cs index 85102887829..f38e739d0a8 100644 --- a/src/CodeGeneration/ApiGenerator/ApiGenerator.cs +++ b/src/CodeGeneration/ApiGenerator/ApiGenerator.cs @@ -27,7 +27,6 @@ public class ApiGenerator "rank_eval.json", // these API's are new and need to be mapped - "xpack.ml.delete_forecast.json", "xpack.ml.find_file_structure.json", "xpack.ml.update_filter.json", diff --git a/src/CodeGeneration/ApiGenerator/Domain/ApiUrlPart.cs b/src/CodeGeneration/ApiGenerator/Domain/ApiUrlPart.cs index 6eb846f2a09..ffb7319bf21 100644 --- a/src/CodeGeneration/ApiGenerator/Domain/ApiUrlPart.cs +++ b/src/CodeGeneration/ApiGenerator/Domain/ApiUrlPart.cs @@ -50,6 +50,7 @@ public string ClrTypeName case "filter_id": case "id": return Type == "string" ? "Id" : "Ids"; case "category_id": return "CategoryId"; + case "forecast_id": return "ForecastIds"; case "nodes": case "node_id": return Type == "string" ? "NodeId" : "NodeIds"; case "scroll_id": return Type == "string" ? "ScrollId" : "ScrollIds"; diff --git a/src/CodeGeneration/ApiGenerator/RestSpecification/XPack/MachineLearning/xpack.ml.delete_forecast.patch.json b/src/CodeGeneration/ApiGenerator/RestSpecification/XPack/MachineLearning/xpack.ml.delete_forecast.patch.json new file mode 100644 index 00000000000..3e7aacf7855 --- /dev/null +++ b/src/CodeGeneration/ApiGenerator/RestSpecification/XPack/MachineLearning/xpack.ml.delete_forecast.patch.json @@ -0,0 +1,16 @@ +{ + "xpack.ml.delete_forecast": { + "url": { + "path": "/_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id}", + "paths": [ + "/_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id}" + ], + "parts": { + "forecast_id": { + "required": true, + "description": "The ID of the forecast to delete, can be comma delimited list or `_all`" + } + } + } + } +} diff --git a/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs b/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs index 0ba171fb2df..9c1b92b53ca 100644 --- a/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs +++ b/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs @@ -2395,6 +2395,15 @@ public partial class DeleteExpiredDataRequestParameters : RequestParameters HttpMethod.DELETE; } + ///Request options for XpackMlDeleteForecast
http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html
+ public partial class DeleteForecastRequestParameters : RequestParameters + { + public override HttpMethod DefaultHttpMethod => HttpMethod.DELETE; + ///Whether to ignore if `_all` matches no forecasts + public bool? AllowNoForecasts { get => Q("allow_no_forecasts"); set => Q("allow_no_forecasts", value); } + ///Controls the time to wait until the forecast(s) are deleted. Default to 30 seconds + public TimeSpan Timeout { get => Q("timeout"); set => Q("timeout", value); } + } ///Request options for XpackMlDeleteJob
http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html
public partial class DeleteJobRequestParameters : RequestParameters { diff --git a/src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs b/src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs index 80278904d0b..ab3dbd1a9ea 100644 --- a/src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs +++ b/src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs @@ -3236,6 +3236,18 @@ public TResponse XpackMlDeleteExpiredData(DeleteExpiredDataRequestPar ///A func that allows you to describe the querystring parameters & request specific connection settings. public Task XpackMlDeleteExpiredDataAsync(DeleteExpiredDataRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync(DELETE, Url($"_xpack/ml/_delete_expired_data"), ctx, null, _params(requestParameters)); + ///DELETE on /_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id} http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html + ///The ID of the job from which to delete forecasts + ///The ID of the forecast to delete, can be comma delimited list or `_all` + ///A func that allows you to describe the querystring parameters & request specific connection settings. + public TResponse XpackMlDeleteForecast(string job_id, string forecast_id, DeleteForecastRequestParameters requestParameters = null) + where TResponse : class, IElasticsearchResponse, new() => this.DoRequest(DELETE, Url($"_xpack/ml/anomaly_detectors/{job_id.NotNull("job_id")}/_forecast/{forecast_id.NotNull("forecast_id")}"), null, _params(requestParameters)); + ///DELETE on /_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id} http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html + ///The ID of the job from which to delete forecasts + ///The ID of the forecast to delete, can be comma delimited list or `_all` + ///A func that allows you to describe the querystring parameters & request specific connection settings. + public Task XpackMlDeleteForecastAsync(string job_id, string forecast_id, DeleteForecastRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) + where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync(DELETE, Url($"_xpack/ml/anomaly_detectors/{job_id.NotNull("job_id")}/_forecast/{forecast_id.NotNull("forecast_id")}"), ctx, null, _params(requestParameters)); ///DELETE on /_xpack/ml/anomaly_detectors/{job_id} http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html ///The ID of the job to delete ///A func that allows you to describe the querystring parameters & request specific connection settings. diff --git a/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs b/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs index 0885375ddb5..a72d047a44a 100644 --- a/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs +++ b/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs @@ -2620,6 +2620,16 @@ public partial interface IElasticLowLevelClient ///DELETE on /_xpack/ml/_delete_expired_data ///A func that allows you to describe the querystring parameters & request specific connection settings. Task XpackMlDeleteExpiredDataAsync(DeleteExpiredDataRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new(); + ///DELETE on /_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id} http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html + ///The ID of the job from which to delete forecasts + ///The ID of the forecast to delete, can be comma delimited list or `_all` + ///A func that allows you to describe the querystring parameters & request specific connection settings. + TResponse XpackMlDeleteForecast(string job_id, string forecast_id, DeleteForecastRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new(); + ///DELETE on /_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id} http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html + ///The ID of the job from which to delete forecasts + ///The ID of the forecast to delete, can be comma delimited list or `_all` + ///A func that allows you to describe the querystring parameters & request specific connection settings. + Task XpackMlDeleteForecastAsync(string job_id, string forecast_id, DeleteForecastRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new(); ///DELETE on /_xpack/ml/anomaly_detectors/{job_id} http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html ///The ID of the job to delete ///A func that allows you to describe the querystring parameters & request specific connection settings. diff --git a/src/Nest/CommonAbstractions/Infer/ForecastIds/ForecastIds.cs b/src/Nest/CommonAbstractions/Infer/ForecastIds/ForecastIds.cs new file mode 100644 index 00000000000..237f26fe594 --- /dev/null +++ b/src/Nest/CommonAbstractions/Infer/ForecastIds/ForecastIds.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Elasticsearch.Net; + +namespace Nest +{ + [DebuggerDisplay("{DebugDisplay,nq}")] + public class ForecastIds : IUrlParameter, IEquatable + { + public static ForecastIds All { get; } = new ForecastIds("_all"); + + private readonly List _forecastIds; + + public ForecastIds(IEnumerable forecastIds) => _forecastIds = forecastIds?.ToList(); + + public ForecastIds(string forecastIds) + { + if (!forecastIds.IsNullOrEmptyCommaSeparatedList(out var ids)) + _forecastIds = ids.ToList(); + } + + private string DebugDisplay => ((IUrlParameter)this).GetString(null); + + public bool Equals(ForecastIds other) + { + if (other == null) return false; + if (_forecastIds == null && other._forecastIds == null) return true; + if (_forecastIds == null || other._forecastIds == null) return false; + + return _forecastIds.Count == other._forecastIds.Count && + _forecastIds.OrderBy(id => id).SequenceEqual(other._forecastIds.OrderBy(id => id)); + } + + string IUrlParameter.GetString(IConnectionConfigurationValues settings) => string.Join(",", _forecastIds ?? Enumerable.Empty()); + + public static implicit operator ForecastIds(string forecastIds) => + forecastIds.IsNullOrEmptyCommaSeparatedList(out var arr) ? null : new ForecastIds(arr); + + public static implicit operator ForecastIds(string[] forecastIds) => + forecastIds.IsEmpty() ? null : new ForecastIds(forecastIds); + + public override bool Equals(object obj) => obj is ForecastIds other && Equals(other); + + public override int GetHashCode() + { + unchecked + { + var hc = 0; + foreach (var id in _forecastIds.OrderBy(id => id)) + hc = hc * 17 + id.GetHashCode(); + return hc; + } + } + + public static bool operator ==(ForecastIds left, ForecastIds right) => Equals(left, right); + + public static bool operator !=(ForecastIds left, ForecastIds right) => !Equals(left, right); + } +} diff --git a/src/Nest/CommonAbstractions/Request/RouteValues.cs b/src/Nest/CommonAbstractions/Request/RouteValues.cs index a8156ce2988..c3ca5d6cda3 100644 --- a/src/Nest/CommonAbstractions/Request/RouteValues.cs +++ b/src/Nest/CommonAbstractions/Request/RouteValues.cs @@ -10,6 +10,7 @@ public class RouteValues public string ActionId => GetResolved("action_id"); public string Alias => GetResolved("alias"); public string CategoryId => GetResolved("category_id"); + public string ForecastId => GetResolved("forecast_id"); public string Context => GetResolved("context"); public string DatafeedId => GetResolved("datafeed_id"); public string Feature => GetResolved("feature"); diff --git a/src/Nest/Document/Multiple/Bulk/BulkRequestJsonConverter.cs b/src/Nest/Document/Multiple/Bulk/BulkRequestJsonConverter.cs index ac65bb699d5..85ca2ba3c67 100644 --- a/src/Nest/Document/Multiple/Bulk/BulkRequestJsonConverter.cs +++ b/src/Nest/Document/Multiple/Bulk/BulkRequestJsonConverter.cs @@ -29,7 +29,11 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s op.Routing = op.GetRoutingForOperation(settings.Inferrer); var opJson = requestResponseSerializer.SerializeToString(op, SerializationFormatting.None); - writer.WriteRaw($"{{\"{op.Operation}\":" + opJson + "}\n"); + writer.WriteRaw("{\""); + writer.WriteRaw(op.Operation); + writer.WriteRaw("\":"); + writer.WriteRaw(opJson); + writer.WriteRaw("}\n"); var body = op.GetBody(); if (body == null) continue; @@ -40,7 +44,8 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s ) .SerializeToString(body, SerializationFormatting.None); - writer.WriteRaw(bodyJson + "\n"); + writer.WriteRaw(bodyJson); + writer.WriteRaw("\n"); } } diff --git a/src/Nest/XPack/MachineLearning/DeleteForecast/DeleteForecastRequest.cs b/src/Nest/XPack/MachineLearning/DeleteForecast/DeleteForecastRequest.cs new file mode 100644 index 00000000000..4132bd32479 --- /dev/null +++ b/src/Nest/XPack/MachineLearning/DeleteForecast/DeleteForecastRequest.cs @@ -0,0 +1,9 @@ +namespace Nest +{ + public partial interface IDeleteForecastRequest { } + + public partial class DeleteForecastRequest { } + + [DescriptorFor("XpackMlDeleteForecast")] + public partial class DeleteForecastDescriptor { } +} diff --git a/src/Nest/XPack/MachineLearning/DeleteForecast/DeleteForecastResponse.cs b/src/Nest/XPack/MachineLearning/DeleteForecast/DeleteForecastResponse.cs new file mode 100644 index 00000000000..ac88ede6ee6 --- /dev/null +++ b/src/Nest/XPack/MachineLearning/DeleteForecast/DeleteForecastResponse.cs @@ -0,0 +1,6 @@ +namespace Nest +{ + public interface IDeleteForecastResponse : IAcknowledgedResponse { } + + public class DeleteForecastResponse : AcknowledgedResponseBase, IDeleteForecastResponse { } +} diff --git a/src/Nest/XPack/MachineLearning/DeleteForecast/ElasticClient-DeleteForecast.cs b/src/Nest/XPack/MachineLearning/DeleteForecast/ElasticClient-DeleteForecast.cs new file mode 100644 index 00000000000..d34d14ad065 --- /dev/null +++ b/src/Nest/XPack/MachineLearning/DeleteForecast/ElasticClient-DeleteForecast.cs @@ -0,0 +1,56 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Elasticsearch.Net; + +namespace Nest +{ + public partial interface IElasticClient + { + /// + /// Deletes forecasts from a machine learning job. + /// + IDeleteForecastResponse DeleteForecast(Id jobId, ForecastIds forecastId, Func selector = null); + + /// + IDeleteForecastResponse DeleteForecast(IDeleteForecastRequest request); + + /// + Task DeleteForecastAsync(Id jobId, ForecastIds forecastId, Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); + + /// + Task DeleteForecastAsync(IDeleteForecastRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); + } + + public partial class ElasticClient + { + /// + public IDeleteForecastResponse DeleteForecast(Id jobId, ForecastIds forecastId, Func selector = null) => + DeleteForecast(selector.InvokeOrDefault(new DeleteForecastDescriptor(jobId, forecastId))); + + /// + public IDeleteForecastResponse DeleteForecast(IDeleteForecastRequest request) => + Dispatcher.Dispatch( + request, + (p, d) => LowLevelDispatch.XpackMlDeleteForecastDispatch(p) + ); + + /// + public Task DeleteForecastAsync(Id jobId, ForecastIds forecastId, + Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => + DeleteForecastAsync(selector.InvokeOrDefault(new DeleteForecastDescriptor(jobId, forecastId)), cancellationToken); + + /// + public Task DeleteForecastAsync(IDeleteForecastRequest request, + CancellationToken cancellationToken = default(CancellationToken)) => + Dispatcher.DispatchAsync( + request, + cancellationToken, + (p, d, c) => LowLevelDispatch.XpackMlDeleteForecastDispatchAsync(p, c) + ); + } +} diff --git a/src/Nest/_Generated/_Descriptors.generated.cs b/src/Nest/_Generated/_Descriptors.generated.cs index 6e0f6735751..6b8cda639ab 100644 --- a/src/Nest/_Generated/_Descriptors.generated.cs +++ b/src/Nest/_Generated/_Descriptors.generated.cs @@ -4232,6 +4232,24 @@ public partial class DeleteExpiredDataDescriptor : RequestDescriptorBasedescriptor for XpackMlDeleteForecast
http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html
+ public partial class DeleteForecastDescriptor : RequestDescriptorBase, IDeleteForecastRequest + { + /// /_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id} + /// this parameter is required + /// this parameter is required + public DeleteForecastDescriptor(Id job_id, ForecastIds forecast_id) : base(r=>r.Required("job_id", job_id).Required("forecast_id", forecast_id)){} + // values part of the url path + Id IDeleteForecastRequest.JobId => Self.RouteValues.Get("job_id"); + ForecastIds IDeleteForecastRequest.ForecastId => Self.RouteValues.Get("forecast_id"); + + // Request parameters + + ///Whether to ignore if `_all` matches no forecasts + public DeleteForecastDescriptor AllowNoForecasts(bool? allowNoForecasts = true) => Qs("allow_no_forecasts", allowNoForecasts); + ///Controls the time to wait until the forecast(s) are deleted. Default to 30 seconds + public DeleteForecastDescriptor Timeout(Time timeout) => Qs("timeout", timeout); + } ///descriptor for XpackMlDeleteJob
http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html
public partial class DeleteJobDescriptor : RequestDescriptorBase, IDeleteJobRequest { diff --git a/src/Nest/_Generated/_LowLevelDispatch.generated.cs b/src/Nest/_Generated/_LowLevelDispatch.generated.cs index 7312d008d8d..04da12a9862 100644 --- a/src/Nest/_Generated/_LowLevelDispatch.generated.cs +++ b/src/Nest/_Generated/_LowLevelDispatch.generated.cs @@ -3506,6 +3506,28 @@ internal partial class LowLevelDispatch throw InvalidDispatch("XpackMlDeleteExpiredData", p, new [] { DELETE }, "/_xpack/ml/_delete_expired_data"); } + internal TResponse XpackMlDeleteForecastDispatch(IRequest p) where TResponse : class, IElasticsearchResponse, new() + { + switch(p.HttpMethod) + { + case DELETE: + if (AllSetNoFallback(p.RouteValues.JobId, p.RouteValues.ForecastId)) return _lowLevel.XpackMlDeleteForecast(p.RouteValues.JobId,p.RouteValues.ForecastId,p.RequestParameters); + break; + } + throw InvalidDispatch("XpackMlDeleteForecast", p, new [] { DELETE }, "/_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id}"); + } + + internal Task XpackMlDeleteForecastDispatchAsync(IRequest p, CancellationToken ct) where TResponse : class, IElasticsearchResponse, new() + { + switch(p.HttpMethod) + { + case DELETE: + if (AllSetNoFallback(p.RouteValues.JobId, p.RouteValues.ForecastId)) return _lowLevel.XpackMlDeleteForecastAsync(p.RouteValues.JobId,p.RouteValues.ForecastId,p.RequestParameters,ct); + break; + } + throw InvalidDispatch("XpackMlDeleteForecast", p, new [] { DELETE }, "/_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id}"); + } + internal TResponse XpackMlDeleteJobDispatch(IRequest p) 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 2215e2eeb0c..5aa4fdfeac8 100644 --- a/src/Nest/_Generated/_Requests.generated.cs +++ b/src/Nest/_Generated/_Requests.generated.cs @@ -1893,6 +1893,30 @@ public partial class DeleteExpiredDataRequest : PlainRequestBase + { + Id JobId { get; } + ForecastIds ForecastId { get; } + } + ///Request parameters for XpackMlDeleteForecast
http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html
+ public partial class DeleteForecastRequest : PlainRequestBase, IDeleteForecastRequest + { + protected IDeleteForecastRequest Self => this; + ////_xpack/ml/anomaly_detectors/{job_id}/_forecast/{forecast_id} + ///this parameter is required + ///this parameter is required + public DeleteForecastRequest(Id job_id, ForecastIds forecast_id) : base(r=>r.Required("job_id", job_id).Required("forecast_id", forecast_id)){} + // values part of the url path + Id IDeleteForecastRequest.JobId => Self.RouteValues.Get("job_id"); + ForecastIds IDeleteForecastRequest.ForecastId => Self.RouteValues.Get("forecast_id"); + + // Request parameters + ///Whether to ignore if `_all` matches no forecasts + public bool? AllowNoForecasts { get => Q("allow_no_forecasts"); set => Q("allow_no_forecasts", value); } + ///Controls the time to wait until the forecast(s) are deleted. Default to 30 seconds + public Time Timeout { get => Q