Skip to content

Commit 2003607

Browse files
committed
Update by query API (#3597)
(cherry picked from commit 04f09fb)
1 parent f3872b8 commit 2003607

File tree

13 files changed

+297
-2
lines changed

13 files changed

+297
-2
lines changed

src/CodeGeneration/ApiGenerator/CodeConfiguration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public static class CodeConfiguration
3838
"ml.find_file_structure.json",
3939
"monitoring.bulk.json",
4040
"delete_by_query_rethrottle.json",
41-
"update_by_query_rethrottle.json",
4241

4342
"security.delete_privileges.json",
4443
"security.get_privileges.json",

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,13 @@ public class UpdateByQueryRequestParameters : RequestParameters<UpdateByQueryReq
22132213
///<summary>The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks.</summary>
22142214
public long? Slices { get => Q<long?>("slices"); set => Q("slices", value); }
22152215
}
2216+
///<summary>Request options for UpdateByQueryRethrottle<pre>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html</pre></summary>
2217+
public class UpdateByQueryRethrottleRequestParameters : RequestParameters<UpdateByQueryRethrottleRequestParameters>
2218+
{
2219+
public override HttpMethod DefaultHttpMethod => HttpMethod.POST;
2220+
///<summary>The throttle to set on this request in floating sub-requests per second. -1 means set no throttle.</summary>
2221+
public long? RequestsPerSecond { get => Q<long?>("requests_per_second"); set => Q("requests_per_second", value); }
2222+
}
22162223
///<summary>Request options for CcrDeleteAutoFollowPattern<pre>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-delete-auto-follow-pattern.html</pre></summary>
22172224
public class DeleteAutoFollowPatternRequestParameters : RequestParameters<DeleteAutoFollowPatternRequestParameters>
22182225
{

src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,6 +2532,16 @@ public TResponse UpdateByQuery<TResponse>(string index, PostData body, UpdateByQ
25322532
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
25332533
public Task<TResponse> UpdateByQueryAsync<TResponse>(string index, PostData body, UpdateByQueryRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken))
25342534
where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync<TResponse>(POST, Url($"{index.NotNull("index")}/_update_by_query"), ctx, body, _params(requestParameters));
2535+
///<summary>POST on /_update_by_query/{task_id}/_rethrottle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html</para></summary>
2536+
///<param name="task_id">The task id to rethrottle</param>
2537+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2538+
public TResponse UpdateByQueryRethrottle<TResponse>(string task_id, UpdateByQueryRethrottleRequestParameters requestParameters = null)
2539+
where TResponse : class, IElasticsearchResponse, new() => this.DoRequest<TResponse>(POST, Url($"_update_by_query/{task_id.NotNull("task_id")}/_rethrottle"), null, _params(requestParameters));
2540+
///<summary>POST on /_update_by_query/{task_id}/_rethrottle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html</para></summary>
2541+
///<param name="task_id">The task id to rethrottle</param>
2542+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2543+
public Task<TResponse> UpdateByQueryRethrottleAsync<TResponse>(string task_id, UpdateByQueryRethrottleRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken))
2544+
where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync<TResponse>(POST, Url($"_update_by_query/{task_id.NotNull("task_id")}/_rethrottle"), ctx, null, _params(requestParameters));
25352545
///<summary>DELETE on /_ccr/auto_follow/{name} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-delete-auto-follow-pattern.html</para></summary>
25362546
///<param name="name">The name of the auto follow pattern.</param>
25372547
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>

src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,14 @@ public partial interface IElasticLowLevelClient
20342034
///<param name="body">The search definition using the Query DSL</param>
20352035
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
20362036
Task<TResponse> UpdateByQueryAsync<TResponse>(string index, PostData body, UpdateByQueryRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new();
2037+
///<summary>POST on /_update_by_query/{task_id}/_rethrottle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html</para></summary>
2038+
///<param name="task_id">The task id to rethrottle</param>
2039+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2040+
TResponse UpdateByQueryRethrottle<TResponse>(string task_id, UpdateByQueryRethrottleRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new();
2041+
///<summary>POST on /_update_by_query/{task_id}/_rethrottle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html</para></summary>
2042+
///<param name="task_id">The task id to rethrottle</param>
2043+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2044+
Task<TResponse> UpdateByQueryRethrottleAsync<TResponse>(string task_id, UpdateByQueryRethrottleRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new();
20372045
///<summary>DELETE on /_ccr/auto_follow/{name} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-delete-auto-follow-pattern.html</para></summary>
20382046
///<param name="name">The name of the auto follow pattern.</param>
20392047
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>

src/Nest/Cluster/TaskManagement/ListTasks/ListTasksResponse.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public class ListTasksResponse : ResponseBase, IListTasksResponse
2424

2525
public class TaskExecutingNode
2626
{
27+
[DataMember(Name = "attributes")]
28+
[JsonFormatter(typeof(VerbatimInterfaceReadOnlyDictionaryKeysFormatter<string, string>))]
29+
public IReadOnlyDictionary<string, string> Attributes { get; internal set; } = EmptyReadOnly<string, string>.Dictionary;
30+
2731
[DataMember(Name = "host")]
2832
public string Host { get; internal set; }
2933

@@ -33,6 +37,9 @@ public class TaskExecutingNode
3337
[DataMember(Name = "name")]
3438
public string Name { get; internal set; }
3539

40+
[DataMember(Name = "roles")]
41+
public IEnumerable<string> Roles { get; internal set; }
42+
3643
[DataMember(Name = "tasks")]
3744
public IReadOnlyDictionary<TaskId, TaskState> Tasks { get; internal set; } = EmptyReadOnly<TaskId, TaskState>.Dictionary;
3845

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Elasticsearch.Net;
5+
6+
namespace Nest
7+
{
8+
public partial interface IElasticClient
9+
{
10+
/// <summary>
11+
/// Rethrottles a running update by query. Rethrottling that speeds up the query takes effect immediately
12+
/// but rethrotting that slows down the query will take effect after completing the current batch. This prevents scroll timeouts.
13+
/// <para> </para>
14+
/// <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html#docs-update-by-query-rethrottle">https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html#docs-update-by-query-rethrottle</a>
15+
/// </summary>
16+
IListTasksResponse UpdateByQueryRethrottle(TaskId taskId, Func<UpdateByQueryRethrottleDescriptor, IUpdateByQueryRethrottleRequest> selector = null);
17+
18+
/// <inheritdoc cref="UpdateByQueryRethrottle(Nest.TaskId,System.Func{Nest.UpdateByQueryRethrottleDescriptor,Nest.IUpdateByQueryRethrottleRequest})" />
19+
IListTasksResponse UpdateByQueryRethrottle(IUpdateByQueryRethrottleRequest request);
20+
21+
/// <inheritdoc cref="UpdateByQueryRethrottle(Nest.TaskId,System.Func{Nest.UpdateByQueryRethrottleDescriptor,Nest.IUpdateByQueryRethrottleRequest})" />
22+
Task<IListTasksResponse> UpdateByQueryRethrottleAsync(TaskId taskId,
23+
Func<UpdateByQueryRethrottleDescriptor, IUpdateByQueryRethrottleRequest> selector = null,
24+
CancellationToken cancellationToken = default(CancellationToken)
25+
);
26+
27+
/// <inheritdoc cref="UpdateByQueryRethrottle(Nest.TaskId,System.Func{Nest.UpdateByQueryRethrottleDescriptor,Nest.IUpdateByQueryRethrottleRequest})" />
28+
Task<IListTasksResponse> UpdateByQueryRethrottleAsync(IUpdateByQueryRethrottleRequest request,
29+
CancellationToken cancellationToken = default(CancellationToken)
30+
);
31+
}
32+
33+
public partial class ElasticClient
34+
{
35+
/// <inheritdoc />
36+
public IListTasksResponse UpdateByQueryRethrottle(TaskId taskId, Func<UpdateByQueryRethrottleDescriptor, IUpdateByQueryRethrottleRequest> selector = null) =>
37+
UpdateByQueryRethrottle(selector.InvokeOrDefault(new UpdateByQueryRethrottleDescriptor(taskId)));
38+
39+
/// <inheritdoc />
40+
public IListTasksResponse UpdateByQueryRethrottle(IUpdateByQueryRethrottleRequest request) =>
41+
Dispatcher.Dispatch<IUpdateByQueryRethrottleRequest, UpdateByQueryRethrottleRequestParameters, ListTasksResponse>(
42+
request,
43+
(p, d) => LowLevelDispatch.UpdateByQueryRethrottleDispatch<ListTasksResponse>(p)
44+
);
45+
46+
/// <inheritdoc />
47+
public Task<IListTasksResponse> UpdateByQueryRethrottleAsync(TaskId taskId, Func<UpdateByQueryRethrottleDescriptor, IUpdateByQueryRethrottleRequest> selector = null,
48+
CancellationToken cancellationToken = default(CancellationToken)
49+
) =>
50+
UpdateByQueryRethrottleAsync(selector.InvokeOrDefault(new UpdateByQueryRethrottleDescriptor(taskId)), cancellationToken);
51+
52+
/// <inheritdoc />
53+
public Task<IListTasksResponse> UpdateByQueryRethrottleAsync(IUpdateByQueryRethrottleRequest request,
54+
CancellationToken cancellationToken = default(CancellationToken)
55+
) =>
56+
Dispatcher.DispatchAsync<IUpdateByQueryRethrottleRequest, UpdateByQueryRethrottleRequestParameters, ListTasksResponse, IListTasksResponse>(
57+
request,
58+
cancellationToken,
59+
(p, d, c) => LowLevelDispatch.UpdateByQueryRethrottleDispatchAsync<ListTasksResponse>(p, c)
60+
);
61+
}
62+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Nest
2+
{
3+
[MapsApi("update_by_query_rethrottle")]
4+
public partial interface IUpdateByQueryRethrottleRequest { }
5+
6+
public partial class UpdateByQueryRethrottleRequest : IUpdateByQueryRethrottleRequest { }
7+
8+
public partial class UpdateByQueryRethrottleDescriptor : IUpdateByQueryRethrottleRequest { }
9+
}

src/Nest/_Generated/_Descriptors.generated.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4024,6 +4024,23 @@ public UpdateByQueryDescriptor() : this(typeof(T)){}
40244024
///<summary>The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks.</summary>
40254025
public UpdateByQueryDescriptor<T> Slices(long? slices) => Qs("slices", slices);
40264026
}
4027+
///<summary>descriptor for UpdateByQueryRethrottle <pre>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html</pre></summary>
4028+
public partial class UpdateByQueryRethrottleDescriptor : RequestDescriptorBase<UpdateByQueryRethrottleDescriptor,UpdateByQueryRethrottleRequestParameters, IUpdateByQueryRethrottleRequest>, IUpdateByQueryRethrottleRequest
4029+
{
4030+
///<summary>/_update_by_query/{task_id}/_rethrottle</summary>
4031+
///<param name="task_id">this parameter is required</param>
4032+
public UpdateByQueryRethrottleDescriptor(TaskId task_id) : base(r => r.Required("task_id", task_id)){}
4033+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
4034+
[SerializationConstructor]
4035+
internal UpdateByQueryRethrottleDescriptor() : base(){}
4036+
// values part of the url path
4037+
TaskId IUpdateByQueryRethrottleRequest.TaskId => Self.RouteValues.Get<TaskId>("task_id");
4038+
4039+
// Request parameters
4040+
4041+
///<summary>The throttle to set on this request in floating sub-requests per second. -1 means set no throttle.</summary>
4042+
public UpdateByQueryRethrottleDescriptor RequestsPerSecond(long? requestsPerSecond) => Qs("requests_per_second", requestsPerSecond);
4043+
}
40274044
///<summary>descriptor for CcrDeleteAutoFollowPattern <pre>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-delete-auto-follow-pattern.html</pre></summary>
40284045
public partial class DeleteAutoFollowPatternDescriptor : RequestDescriptorBase<DeleteAutoFollowPatternDescriptor,DeleteAutoFollowPatternRequestParameters, IDeleteAutoFollowPatternRequest>, IDeleteAutoFollowPatternRequest
40294046
{

src/Nest/_Generated/_LowLevelDispatch.generated.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,6 +2866,28 @@ internal partial class LowLevelDispatch
28662866
throw InvalidDispatch("UpdateByQuery", p, new [] { POST }, "/{index}/_update_by_query");
28672867
}
28682868

2869+
internal TResponse UpdateByQueryRethrottleDispatch<TResponse>(IRequest<UpdateByQueryRethrottleRequestParameters> p) where TResponse : class, IElasticsearchResponse, new()
2870+
{
2871+
switch(p.HttpMethod)
2872+
{
2873+
case POST:
2874+
if (AllSetNoFallback(p.RouteValues.TaskId)) return _lowLevel.UpdateByQueryRethrottle<TResponse>(p.RouteValues.TaskId,p.RequestParameters);
2875+
break;
2876+
}
2877+
throw InvalidDispatch("UpdateByQueryRethrottle", p, new [] { POST }, "/_update_by_query/{task_id}/_rethrottle");
2878+
}
2879+
2880+
internal Task<TResponse> UpdateByQueryRethrottleDispatchAsync<TResponse>(IRequest<UpdateByQueryRethrottleRequestParameters> p, CancellationToken ct) where TResponse : class, IElasticsearchResponse, new()
2881+
{
2882+
switch(p.HttpMethod)
2883+
{
2884+
case POST:
2885+
if (AllSetNoFallback(p.RouteValues.TaskId)) return _lowLevel.UpdateByQueryRethrottleAsync<TResponse>(p.RouteValues.TaskId,p.RequestParameters,ct);
2886+
break;
2887+
}
2888+
throw InvalidDispatch("UpdateByQueryRethrottle", p, new [] { POST }, "/_update_by_query/{task_id}/_rethrottle");
2889+
}
2890+
28692891
internal TResponse CcrDeleteAutoFollowPatternDispatch<TResponse>(IRequest<DeleteAutoFollowPatternRequestParameters> p) where TResponse : class, IElasticsearchResponse, new()
28702892
{
28712893
switch(p.HttpMethod)

src/Nest/_Generated/_Requests.generated.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6609,6 +6609,31 @@ public UpdateByQueryRequest(Indices index) : base(index){}
66096609
public UpdateByQueryRequest() : base(typeof(T)){}
66106610
}
66116611

6612+
[InterfaceDataContract]
6613+
public partial interface IUpdateByQueryRethrottleRequest : IRequest<UpdateByQueryRethrottleRequestParameters>
6614+
{
6615+
[IgnoreDataMember]
6616+
TaskId TaskId { get; }
6617+
}
6618+
6619+
///<summary>Request parameters for UpdateByQueryRethrottle <pre>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html</pre></summary>
6620+
public partial class UpdateByQueryRethrottleRequest : PlainRequestBase<UpdateByQueryRethrottleRequestParameters>, IUpdateByQueryRethrottleRequest
6621+
{
6622+
protected IUpdateByQueryRethrottleRequest Self => this;
6623+
///<summary>/_update_by_query/{task_id}/_rethrottle</summary>
6624+
///<param name="task_id">this parameter is required</param>
6625+
public UpdateByQueryRethrottleRequest(TaskId task_id) : base(r => r.Required("task_id", task_id)){}
6626+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
6627+
[SerializationConstructor]
6628+
internal UpdateByQueryRethrottleRequest() : base(){}
6629+
// values part of the url path
6630+
[IgnoreDataMember]
6631+
TaskId IUpdateByQueryRethrottleRequest.TaskId => Self.RouteValues.Get<TaskId>("task_id");
6632+
6633+
// Request parameters
6634+
///<summary>The throttle to set on this request in floating sub-requests per second. -1 means set no throttle.</summary>
6635+
public long? RequestsPerSecond { get => Q<long?>("requests_per_second"); set => Q("requests_per_second", value); }
6636+
}
66126637
[InterfaceDataContract]
66136638
public partial interface IUpdateDatafeedRequest : IRequest<UpdateDatafeedRequestParameters>
66146639
{

0 commit comments

Comments
 (0)