Skip to content

Commit afa8a7c

Browse files
authored
Update by query API (#3597)
1 parent 25226cc commit afa8a7c

File tree

13 files changed

+297
-2
lines changed

13 files changed

+297
-2
lines changed

src/CodeGeneration/ApiGenerator/ApiGenerator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public class ApiGenerator
3030
"xpack.ml.delete_forecast.json",
3131
"xpack.ml.find_file_structure.json",
3232
"delete_by_query_rethrottle.json",
33-
"update_by_query_rethrottle.json",
3433

3534
"xpack.ml.update_filter.json",
3635
"xpack.security.delete_privileges.json",

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,6 +2230,13 @@ public partial class UpdateByQueryRequestParameters : RequestParameters<UpdateBy
22302230
///<summary>The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks.</summary>
22312231
public long? Slices { get => Q<long?>("slices"); set => Q("slices", value); }
22322232
}
2233+
///<summary>Request options for UpdateByQueryRethrottle<pre>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html</pre></summary>
2234+
public partial class UpdateByQueryRethrottleRequestParameters : RequestParameters<UpdateByQueryRethrottleRequestParameters>
2235+
{
2236+
public override HttpMethod DefaultHttpMethod => HttpMethod.POST;
2237+
///<summary>The throttle to set on this request in floating sub-requests per second. -1 means set no throttle.</summary>
2238+
public long? RequestsPerSecond { get => Q<long?>("requests_per_second"); set => Q("requests_per_second", value); }
2239+
}
22332240
///<summary>Request options for CcrDeleteAutoFollowPattern<pre>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-delete-auto-follow-pattern.html</pre></summary>
22342241
public partial class DeleteAutoFollowPatternRequestParameters : RequestParameters<DeleteAutoFollowPatternRequestParameters>
22352242
{

src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,16 @@ public TResponse UpdateByQuery<TResponse>(string index, string type, PostData bo
29302930
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
29312931
public Task<TResponse> UpdateByQueryAsync<TResponse>(string index, string type, PostData body, UpdateByQueryRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken))
29322932
where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync<TResponse>(POST, Url($"{index.NotNull("index")}/{type.NotNull("type")}/_update_by_query"), ctx, body, _params(requestParameters));
2933+
///<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>
2934+
///<param name="task_id">The task id to rethrottle</param>
2935+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2936+
public TResponse UpdateByQueryRethrottle<TResponse>(string task_id, UpdateByQueryRethrottleRequestParameters requestParameters = null)
2937+
where TResponse : class, IElasticsearchResponse, new() => this.DoRequest<TResponse>(POST, Url($"_update_by_query/{task_id.NotNull("task_id")}/_rethrottle"), null, _params(requestParameters));
2938+
///<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>
2939+
///<param name="task_id">The task id to rethrottle</param>
2940+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2941+
public Task<TResponse> UpdateByQueryRethrottleAsync<TResponse>(string task_id, UpdateByQueryRethrottleRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken))
2942+
where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync<TResponse>(POST, Url($"_update_by_query/{task_id.NotNull("task_id")}/_rethrottle"), ctx, null, _params(requestParameters));
29332943
///<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>
29342944
///<param name="name">The name of the auto follow pattern.</param>
29352945
///<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
@@ -2376,6 +2376,14 @@ public partial interface IElasticLowLevelClient
23762376
///<param name="body">The search definition using the Query DSL</param>
23772377
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
23782378
Task<TResponse> UpdateByQueryAsync<TResponse>(string index, string type, PostData body, UpdateByQueryRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new();
2379+
///<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>
2380+
///<param name="task_id">The task id to rethrottle</param>
2381+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2382+
TResponse UpdateByQueryRethrottle<TResponse>(string task_id, UpdateByQueryRethrottleRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new();
2383+
///<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>
2384+
///<param name="task_id">The task id to rethrottle</param>
2385+
///<param name="requestParameters">A func that allows you to describe the querystring parameters &amp; request specific connection settings.</param>
2386+
Task<TResponse> UpdateByQueryRethrottleAsync<TResponse>(string task_id, UpdateByQueryRethrottleRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new();
23792387
///<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>
23802388
///<param name="name">The name of the auto follow pattern.</param>
23812389
///<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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public class ListTasksResponse : ResponseBase, IListTasksResponse
2424

2525
public class TaskExecutingNode
2626
{
27+
[JsonProperty("attributes")]
28+
[JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter<string, string>))]
29+
public IReadOnlyDictionary<string, string> Attributes { get; internal set; } =
30+
EmptyReadOnly<string, string>.Dictionary;
31+
2732
[JsonProperty("host")]
2833
public string Host { get; internal set; }
2934

@@ -33,6 +38,9 @@ public class TaskExecutingNode
3338
[JsonProperty("name")]
3439
public string Name { get; internal set; }
3540

41+
[JsonProperty("roles")]
42+
public IEnumerable<string> Roles { get; internal set; }
43+
3644
[JsonProperty("tasks")]
3745
public IReadOnlyDictionary<TaskId, TaskState> Tasks { get; internal set; } = EmptyReadOnly<TaskId, TaskState>.Dictionary;
3846

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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace Nest
5+
{
6+
public partial interface IUpdateByQueryRethrottleRequest
7+
{
8+
}
9+
10+
public partial class UpdateByQueryRethrottleRequest: IUpdateByQueryRethrottleRequest
11+
{
12+
}
13+
14+
public partial class UpdateByQueryRethrottleDescriptor : IUpdateByQueryRethrottleRequest
15+
{
16+
}
17+
}

src/Nest/_Generated/_Descriptors.generated.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3859,6 +3859,20 @@ public UpdateByQueryDescriptor(Indices index) : base(r=>r.Required("index", inde
38593859
///<summary>The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks.</summary>
38603860
public UpdateByQueryDescriptor<T> Slices(long? slices) => Qs("slices", slices);
38613861
}
3862+
///<summary>descriptor for UpdateByQueryRethrottle <pre>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html</pre></summary>
3863+
public partial class UpdateByQueryRethrottleDescriptor : RequestDescriptorBase<UpdateByQueryRethrottleDescriptor,UpdateByQueryRethrottleRequestParameters, IUpdateByQueryRethrottleRequest>, IUpdateByQueryRethrottleRequest
3864+
{
3865+
/// <summary>/_update_by_query/{task_id}/_rethrottle</summary>
3866+
///<param name="task_id"> this parameter is required</param>
3867+
public UpdateByQueryRethrottleDescriptor(TaskId task_id) : base(r=>r.Required("task_id", task_id)){}
3868+
// values part of the url path
3869+
TaskId IUpdateByQueryRethrottleRequest.TaskId => Self.RouteValues.Get<TaskId>("task_id");
3870+
3871+
// Request parameters
3872+
3873+
///<summary>The throttle to set on this request in floating sub-requests per second. -1 means set no throttle.</summary>
3874+
public UpdateByQueryRethrottleDescriptor RequestsPerSecond(long? requestsPerSecond) => Qs("requests_per_second", requestsPerSecond);
3875+
}
38623876
///<summary>descriptor for CcrDeleteAutoFollowPattern <pre>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-delete-auto-follow-pattern.html</pre></summary>
38633877
public partial class DeleteAutoFollowPatternDescriptor : RequestDescriptorBase<DeleteAutoFollowPatternDescriptor,DeleteAutoFollowPatternRequestParameters, IDeleteAutoFollowPatternRequest>, IDeleteAutoFollowPatternRequest
38643878
{

src/Nest/_Generated/_LowLevelDispatch.generated.cs

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

2927+
internal TResponse UpdateByQueryRethrottleDispatch<TResponse>(IRequest<UpdateByQueryRethrottleRequestParameters> p) where TResponse : class, IElasticsearchResponse, new()
2928+
{
2929+
switch(p.HttpMethod)
2930+
{
2931+
case POST:
2932+
if (AllSetNoFallback(p.RouteValues.TaskId)) return _lowLevel.UpdateByQueryRethrottle<TResponse>(p.RouteValues.TaskId,p.RequestParameters);
2933+
break;
2934+
}
2935+
throw InvalidDispatch("UpdateByQueryRethrottle", p, new [] { POST }, "/_update_by_query/{task_id}/_rethrottle");
2936+
}
2937+
2938+
internal Task<TResponse> UpdateByQueryRethrottleDispatchAsync<TResponse>(IRequest<UpdateByQueryRethrottleRequestParameters> p, CancellationToken ct) where TResponse : class, IElasticsearchResponse, new()
2939+
{
2940+
switch(p.HttpMethod)
2941+
{
2942+
case POST:
2943+
if (AllSetNoFallback(p.RouteValues.TaskId)) return _lowLevel.UpdateByQueryRethrottleAsync<TResponse>(p.RouteValues.TaskId,p.RequestParameters,ct);
2944+
break;
2945+
}
2946+
throw InvalidDispatch("UpdateByQueryRethrottle", p, new [] { POST }, "/_update_by_query/{task_id}/_rethrottle");
2947+
}
2948+
29272949
internal TResponse CcrDeleteAutoFollowPatternDispatch<TResponse>(IRequest<DeleteAutoFollowPatternRequestParameters> p) where TResponse : class, IElasticsearchResponse, new()
29282950
{
29292951
switch(p.HttpMethod)

src/Nest/_Generated/_Requests.generated.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6277,6 +6277,25 @@ public UpdateByQueryRequest(Indices index, Types type) : base(r=>r.Required("ind
62776277
public long? Slices { get => Q<long?>("slices"); set => Q("slices", value); }
62786278
}
62796279
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
6280+
public partial interface IUpdateByQueryRethrottleRequest : IRequest<UpdateByQueryRethrottleRequestParameters>
6281+
{
6282+
TaskId TaskId { get; }
6283+
}
6284+
///<summary>Request parameters for UpdateByQueryRethrottle <pre>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html</pre></summary>
6285+
public partial class UpdateByQueryRethrottleRequest : PlainRequestBase<UpdateByQueryRethrottleRequestParameters>, IUpdateByQueryRethrottleRequest
6286+
{
6287+
protected IUpdateByQueryRethrottleRequest Self => this;
6288+
///<summary>/_update_by_query/{task_id}/_rethrottle</summary>
6289+
///<param name="task_id">this parameter is required</param>
6290+
public UpdateByQueryRethrottleRequest(TaskId task_id) : base(r=>r.Required("task_id", task_id)){}
6291+
// values part of the url path
6292+
TaskId IUpdateByQueryRethrottleRequest.TaskId => Self.RouteValues.Get<TaskId>("task_id");
6293+
6294+
// Request parameters
6295+
///<summary>The throttle to set on this request in floating sub-requests per second. -1 means set no throttle.</summary>
6296+
public long? RequestsPerSecond { get => Q<long?>("requests_per_second"); set => Q("requests_per_second", value); }
6297+
}
6298+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
62806299
public partial interface IUpdateDatafeedRequest : IRequest<UpdateDatafeedRequestParameters>
62816300
{
62826301
Id DatafeedId { get; }

0 commit comments

Comments
 (0)