Skip to content

Commit

Permalink
Delete by query rethrottle API (#3595)
Browse files Browse the repository at this point in the history
* download specs from v6.6.2 tag
* Delete by Query rethrottle API
* exclude DeleteByQueryRethrottle API from naming conventions

(cherry picked from commit 220b2dc)
  • Loading branch information
russcam committed Apr 2, 2019
1 parent 928b681 commit 3d17791
Show file tree
Hide file tree
Showing 18 changed files with 1,026 additions and 3,448 deletions.
1 change: 0 additions & 1 deletion src/CodeGeneration/ApiGenerator/CodeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static class CodeConfiguration
"ml.set_upgrade_mode.json",
"ml.find_file_structure.json",
"monitoring.bulk.json",
"delete_by_query_rethrottle.json",

"security.delete_privileges.json",
"security.get_privileges.json",
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGeneration/ApiGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static void Main(string[] args)

if (redownloadCoreSpecification)
{
Console.Write("Branch to download specification from (default master): ");
Console.Write($"Branch to download specification from (default {downloadBranch}): ");
var readBranch = Console.ReadLine()?.Trim();
if (!string.IsNullOrEmpty(readBranch)) downloadBranch = readBranch;
}
Expand Down
4,153 changes: 717 additions & 3,436 deletions src/CodeGeneration/ApiGenerator/RestSpecification/Core/root.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.4
v6.6.2
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,13 @@ public class DeleteByQueryRequestParameters : RequestParameters<DeleteByQueryReq
///<summary>The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks.</summary>
public long? Slices { get => Q<long?>("slices"); set => Q("slices", value); }
}
///<summary>Request options for DeleteByQueryRethrottle<pre>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html</pre></summary>
public class DeleteByQueryRethrottleRequestParameters : RequestParameters<DeleteByQueryRethrottleRequestParameters>
{
public override HttpMethod DefaultHttpMethod => HttpMethod.POST;
///<summary>The throttle to set on this request in floating sub-requests per second. -1 means set no throttle.</summary>
public long? RequestsPerSecond { get => Q<long?>("requests_per_second"); set => Q("requests_per_second", value); }
}
///<summary>Request options for DeleteScript<pre>http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html</pre></summary>
public class DeleteScriptRequestParameters : RequestParameters<DeleteScriptRequestParameters>
{
Expand Down
10 changes: 10 additions & 0 deletions src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,16 @@ public TResponse DeleteByQuery<TResponse>(string index, PostData body, DeleteByQ
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
public Task<TResponse> DeleteByQueryAsync<TResponse>(string index, PostData body, DeleteByQueryRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken))
where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync<TResponse>(POST, Url($"{index.NotNull("index")}/_delete_by_query"), ctx, body, _params(requestParameters));
///<summary>POST on /_delete_by_query/{task_id}/_rethrottle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html</para></summary>
///<param name="task_id">The task id to rethrottle</param>
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
public TResponse DeleteByQueryRethrottle<TResponse>(string task_id, DeleteByQueryRethrottleRequestParameters requestParameters = null)
where TResponse : class, IElasticsearchResponse, new() => this.DoRequest<TResponse>(POST, Url($"_delete_by_query/{task_id.NotNull("task_id")}/_rethrottle"), null, _params(requestParameters));
///<summary>POST on /_delete_by_query/{task_id}/_rethrottle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html</para></summary>
///<param name="task_id">The task id to rethrottle</param>
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
public Task<TResponse> DeleteByQueryRethrottleAsync<TResponse>(string task_id, DeleteByQueryRethrottleRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken))
where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync<TResponse>(POST, Url($"_delete_by_query/{task_id.NotNull("task_id")}/_rethrottle"), ctx, null, _params(requestParameters));
///<summary>DELETE on /_scripts/{id} <para>http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html</para></summary>
///<param name="id">Script ID</param>
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
Expand Down
8 changes: 8 additions & 0 deletions src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,14 @@ public partial interface IElasticLowLevelClient
///<param name="body">The search definition using the Query DSL</param>
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
Task<TResponse> DeleteByQueryAsync<TResponse>(string index, PostData body, DeleteByQueryRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new();
///<summary>POST on /_delete_by_query/{task_id}/_rethrottle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html</para></summary>
///<param name="task_id">The task id to rethrottle</param>
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
TResponse DeleteByQueryRethrottle<TResponse>(string task_id, DeleteByQueryRethrottleRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new();
///<summary>POST on /_delete_by_query/{task_id}/_rethrottle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html</para></summary>
///<param name="task_id">The task id to rethrottle</param>
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
Task<TResponse> DeleteByQueryRethrottleAsync<TResponse>(string task_id, DeleteByQueryRethrottleRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new();
///<summary>DELETE on /_scripts/{id} <para>http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html</para></summary>
///<param name="id">Script ID</param>
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
Expand Down
3 changes: 2 additions & 1 deletion src/Elasticsearch.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,5 @@
<s:String x:Key="/Default/PatternsAndTemplates/Todo/TodoPatterns/=B68C83B0AE11204AAA509A6033251E74/Name/@EntryValue">Hack</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/Todo/TodoPatterns/=B68C83B0AE11204AAA509A6033251E74/Pattern/@EntryValue">(?&lt;=\W|^)(?&lt;TAG&gt;HACK)(\W|$)(.*)</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/Todo/TodoPatterns/=B68C83B0AE11204AAA509A6033251E74/TodoIconStyle/@EntryValue">Warning</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Rethrottle/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ public class ListTasksResponse : ResponseBase, IListTasksResponse
{
public override bool IsValid => base.IsValid && !NodeFailures.HasAny();
public IReadOnlyCollection<ErrorCause> NodeFailures { get; internal set; } = EmptyReadOnly<ErrorCause>.Collection;

public IReadOnlyDictionary<string, TaskExecutingNode> Nodes { get; internal set; } = EmptyReadOnly<string, TaskExecutingNode>.Dictionary;
}

/// <summary>
/// A node executing a task
/// </summary>
public class TaskExecutingNode
{
[DataMember(Name = "attributes")]
Expand All @@ -47,6 +49,9 @@ public class TaskExecutingNode
public string TransportAddress { get; internal set; }
}

/// <summary>
/// The state of the task
/// </summary>
public class TaskState
{
[DataMember(Name = "action")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Nest
{
/// <summary>
/// Rethrottles a running delete by query
/// </summary>
[MapsApi("delete_by_query_rethrottle")]
public partial interface IDeleteByQueryRethrottleRequest { }

/// <inheritdoc cref="IDeleteByQueryRethrottleRequest" />
public partial class DeleteByQueryRethrottleRequest : IDeleteByQueryRethrottleRequest { }

/// <inheritdoc cref="IDeleteByQueryRethrottleRequest" />
public partial class DeleteByQueryRethrottleDescriptor : IDeleteByQueryRethrottleRequest { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Elasticsearch.Net;

namespace Nest
{
public partial interface IElasticClient
{
/// <summary>
/// Rethrottles a running delete by query. Rethrottling that speeds up the query takes effect immediately
/// but rethrotting that slows down the query will take effect after completing the current batch. This prevents scroll timeouts.
/// <para> </para>
/// <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html#docs-delete-by-query-rethrottle">https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html#docs-delete-by-query-rethrottle</a>
/// </summary>
IListTasksResponse DeleteByQueryRethrottle(TaskId taskId, Func<DeleteByQueryRethrottleDescriptor, IDeleteByQueryRethrottleRequest> selector = null);

/// <inheritdoc cref="DeleteByQueryRethrottle(Nest.TaskId,System.Func{Nest.DeleteByQueryRethrottleDescriptor,Nest.IDeleteByQueryRethrottleRequest})" />
IListTasksResponse DeleteByQueryRethrottle(IDeleteByQueryRethrottleRequest request);

/// <inheritdoc cref="DeleteByQueryRethrottle(Nest.TaskId,System.Func{Nest.DeleteByQueryRethrottleDescriptor,Nest.IDeleteByQueryRethrottleRequest})" />
Task<IListTasksResponse> DeleteByQueryRethrottleAsync(TaskId taskId,
Func<DeleteByQueryRethrottleDescriptor, IDeleteByQueryRethrottleRequest> selector = null,
CancellationToken cancellationToken = default(CancellationToken)
);

/// <inheritdoc cref="DeleteByQueryRethrottle(Nest.TaskId,System.Func{Nest.DeleteByQueryRethrottleDescriptor,Nest.IDeleteByQueryRethrottleRequest})" />
Task<IListTasksResponse> DeleteByQueryRethrottleAsync(IDeleteByQueryRethrottleRequest request,
CancellationToken cancellationToken = default(CancellationToken)
);
}

public partial class ElasticClient
{
/// <inheritdoc />
public IListTasksResponse DeleteByQueryRethrottle(TaskId taskId, Func<DeleteByQueryRethrottleDescriptor, IDeleteByQueryRethrottleRequest> selector = null) =>
DeleteByQueryRethrottle(selector.InvokeOrDefault(new DeleteByQueryRethrottleDescriptor(taskId)));

/// <inheritdoc />
public IListTasksResponse DeleteByQueryRethrottle(IDeleteByQueryRethrottleRequest request) =>
Dispatcher.Dispatch<IDeleteByQueryRethrottleRequest, DeleteByQueryRethrottleRequestParameters, ListTasksResponse>(
request,
(p, d) => LowLevelDispatch.DeleteByQueryRethrottleDispatch<ListTasksResponse>(p)
);

/// <inheritdoc />
public Task<IListTasksResponse> DeleteByQueryRethrottleAsync(TaskId taskId, Func<DeleteByQueryRethrottleDescriptor, IDeleteByQueryRethrottleRequest> selector = null,
CancellationToken cancellationToken = default(CancellationToken)
) =>
DeleteByQueryRethrottleAsync(selector.InvokeOrDefault(new DeleteByQueryRethrottleDescriptor(taskId)), cancellationToken);

/// <inheritdoc />
public Task<IListTasksResponse> DeleteByQueryRethrottleAsync(IDeleteByQueryRethrottleRequest request,
CancellationToken cancellationToken = default(CancellationToken)
) =>
Dispatcher.DispatchAsync<IDeleteByQueryRethrottleRequest, DeleteByQueryRethrottleRequestParameters, ListTasksResponse, IListTasksResponse>(
request,
cancellationToken,
(p, d, c) => LowLevelDispatch.DeleteByQueryRethrottleDispatchAsync<ListTasksResponse>(p, c)
);
}
}
17 changes: 17 additions & 0 deletions src/Nest/_Generated/_Descriptors.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,23 @@ public DeleteByQueryDescriptor() : this(typeof(T)){}
///<summary>The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks.</summary>
public DeleteByQueryDescriptor<T> Slices(long? slices) => Qs("slices", slices);
}
///<summary>descriptor for DeleteByQueryRethrottle <pre>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html</pre></summary>
public partial class DeleteByQueryRethrottleDescriptor : RequestDescriptorBase<DeleteByQueryRethrottleDescriptor,DeleteByQueryRethrottleRequestParameters, IDeleteByQueryRethrottleRequest>, IDeleteByQueryRethrottleRequest
{
///<summary>/_delete_by_query/{task_id}/_rethrottle</summary>
///<param name="task_id">this parameter is required</param>
public DeleteByQueryRethrottleDescriptor(TaskId task_id) : base(r => r.Required("task_id", task_id)){}
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
[SerializationConstructor]
internal DeleteByQueryRethrottleDescriptor() : base(){}
// values part of the url path
TaskId IDeleteByQueryRethrottleRequest.TaskId => Self.RouteValues.Get<TaskId>("task_id");

// Request parameters

///<summary>The throttle to set on this request in floating sub-requests per second. -1 means set no throttle.</summary>
public DeleteByQueryRethrottleDescriptor RequestsPerSecond(long? requestsPerSecond) => Qs("requests_per_second", requestsPerSecond);
}
///<summary>descriptor for DeleteScript <pre>http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html</pre></summary>
public partial class DeleteScriptDescriptor : RequestDescriptorBase<DeleteScriptDescriptor,DeleteScriptRequestParameters, IDeleteScriptRequest>, IDeleteScriptRequest
{
Expand Down
22 changes: 22 additions & 0 deletions src/Nest/_Generated/_LowLevelDispatch.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,28 @@ internal partial class LowLevelDispatch
throw InvalidDispatch("DeleteByQuery", p, new [] { POST }, "/{index}/_delete_by_query");
}

internal TResponse DeleteByQueryRethrottleDispatch<TResponse>(IRequest<DeleteByQueryRethrottleRequestParameters> p) where TResponse : class, IElasticsearchResponse, new()
{
switch(p.HttpMethod)
{
case POST:
if (AllSetNoFallback(p.RouteValues.TaskId)) return _lowLevel.DeleteByQueryRethrottle<TResponse>(p.RouteValues.TaskId,p.RequestParameters);
break;
}
throw InvalidDispatch("DeleteByQueryRethrottle", p, new [] { POST }, "/_delete_by_query/{task_id}/_rethrottle");
}

internal Task<TResponse> DeleteByQueryRethrottleDispatchAsync<TResponse>(IRequest<DeleteByQueryRethrottleRequestParameters> p, CancellationToken ct) where TResponse : class, IElasticsearchResponse, new()
{
switch(p.HttpMethod)
{
case POST:
if (AllSetNoFallback(p.RouteValues.TaskId)) return _lowLevel.DeleteByQueryRethrottleAsync<TResponse>(p.RouteValues.TaskId,p.RequestParameters,ct);
break;
}
throw InvalidDispatch("DeleteByQueryRethrottle", p, new [] { POST }, "/_delete_by_query/{task_id}/_rethrottle");
}

internal TResponse DeleteScriptDispatch<TResponse>(IRequest<DeleteScriptRequestParameters> p) where TResponse : class, IElasticsearchResponse, new()
{
switch(p.HttpMethod)
Expand Down
25 changes: 25 additions & 0 deletions src/Nest/_Generated/_Requests.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,31 @@ public DeleteByQueryRequest(Indices index) : base(index){}
public DeleteByQueryRequest() : base(typeof(T)){}
}

[InterfaceDataContract]
public partial interface IDeleteByQueryRethrottleRequest : IRequest<DeleteByQueryRethrottleRequestParameters>
{
[IgnoreDataMember]
TaskId TaskId { get; }
}

///<summary>Request parameters for DeleteByQueryRethrottle <pre>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html</pre></summary>
public partial class DeleteByQueryRethrottleRequest : PlainRequestBase<DeleteByQueryRethrottleRequestParameters>, IDeleteByQueryRethrottleRequest
{
protected IDeleteByQueryRethrottleRequest Self => this;
///<summary>/_delete_by_query/{task_id}/_rethrottle</summary>
///<param name="task_id">this parameter is required</param>
public DeleteByQueryRethrottleRequest(TaskId task_id) : base(r => r.Required("task_id", task_id)){}
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
[SerializationConstructor]
internal DeleteByQueryRethrottleRequest() : base(){}
// values part of the url path
[IgnoreDataMember]
TaskId IDeleteByQueryRethrottleRequest.TaskId => Self.RouteValues.Get<TaskId>("task_id");

// Request parameters
///<summary>The throttle to set on this request in floating sub-requests per second. -1 means set no throttle.</summary>
public long? RequestsPerSecond { get => Q<long?>("requests_per_second"); set => Q("requests_per_second", value); }
}
[InterfaceDataContract]
public partial interface IDeleteCalendarEventRequest : IRequest<DeleteCalendarEventRequestParameters>
{
Expand Down
11 changes: 4 additions & 7 deletions src/Tests/Tests.Configuration/tests.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
# tracked by git).

# mode either u (unit test), i (integration test) or m (mixed mode)
mode: u
mode: m

# the elasticsearch version that should be started
# Can be a snapshot version of sonatype or "latest" to get the latest snapshot of sonatype
elasticsearch_version: 7.0.0-beta1
elasticsearch_version: 6.6.2
# cluster filter allows you to only run the integration tests of a particular cluster (cluster suffix not needed)
# cluster_filter:
# whether we want to forcefully reseed on the node, if you are starting the tests with a node already running
Expand All @@ -20,8 +21,4 @@ test_against_already_running_elasticsearch: true

#random_source_serializer: true
#random_old_connection: true
seed: 12036

# Can be helpful to speed up tests runs as setting this to true only randomly tests a single overload of the api rather than all 4.
# Can also help keep the noise down in case of test failures
test_only_one: false
#seed: 69819
1 change: 1 addition & 0 deletions src/Tests/Tests/CodeStandards/NamingConventions.doc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void ParityBetweenRequestsAndResponses()
typeof(RenderSearchTemplateRequest),
typeof(MultiSearchTemplateRequest),
typeof(CreateRequest<>),
typeof(DeleteByQueryRethrottleRequest), // uses ListTasksResponse
typeof(UpdateByQueryRethrottleRequest) // uses ListTasksResponse
};

Expand Down
Loading

0 comments on commit 3d17791

Please sign in to comment.