-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
297 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/Nest/Document/Multiple/UpdateByQueryRethrottle/ElasticClient-UpdateByQueryRethrottle.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 update 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-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> | ||
/// </summary> | ||
IListTasksResponse UpdateByQueryRethrottle(TaskId taskId, Func<UpdateByQueryRethrottleDescriptor, IUpdateByQueryRethrottleRequest> selector = null); | ||
|
||
/// <inheritdoc cref="UpdateByQueryRethrottle(Nest.TaskId,System.Func{Nest.UpdateByQueryRethrottleDescriptor,Nest.IUpdateByQueryRethrottleRequest})" /> | ||
IListTasksResponse UpdateByQueryRethrottle(IUpdateByQueryRethrottleRequest request); | ||
|
||
/// <inheritdoc cref="UpdateByQueryRethrottle(Nest.TaskId,System.Func{Nest.UpdateByQueryRethrottleDescriptor,Nest.IUpdateByQueryRethrottleRequest})" /> | ||
Task<IListTasksResponse> UpdateByQueryRethrottleAsync(TaskId taskId, | ||
Func<UpdateByQueryRethrottleDescriptor, IUpdateByQueryRethrottleRequest> selector = null, | ||
CancellationToken cancellationToken = default(CancellationToken) | ||
); | ||
|
||
/// <inheritdoc cref="UpdateByQueryRethrottle(Nest.TaskId,System.Func{Nest.UpdateByQueryRethrottleDescriptor,Nest.IUpdateByQueryRethrottleRequest})" /> | ||
Task<IListTasksResponse> UpdateByQueryRethrottleAsync(IUpdateByQueryRethrottleRequest request, | ||
CancellationToken cancellationToken = default(CancellationToken) | ||
); | ||
} | ||
|
||
public partial class ElasticClient | ||
{ | ||
/// <inheritdoc /> | ||
public IListTasksResponse UpdateByQueryRethrottle(TaskId taskId, Func<UpdateByQueryRethrottleDescriptor, IUpdateByQueryRethrottleRequest> selector = null) => | ||
UpdateByQueryRethrottle(selector.InvokeOrDefault(new UpdateByQueryRethrottleDescriptor(taskId))); | ||
|
||
/// <inheritdoc /> | ||
public IListTasksResponse UpdateByQueryRethrottle(IUpdateByQueryRethrottleRequest request) => | ||
Dispatcher.Dispatch<IUpdateByQueryRethrottleRequest, UpdateByQueryRethrottleRequestParameters, ListTasksResponse>( | ||
request, | ||
(p, d) => LowLevelDispatch.UpdateByQueryRethrottleDispatch<ListTasksResponse>(p) | ||
); | ||
|
||
/// <inheritdoc /> | ||
public Task<IListTasksResponse> UpdateByQueryRethrottleAsync(TaskId taskId, Func<UpdateByQueryRethrottleDescriptor, IUpdateByQueryRethrottleRequest> selector = null, | ||
CancellationToken cancellationToken = default(CancellationToken) | ||
) => | ||
UpdateByQueryRethrottleAsync(selector.InvokeOrDefault(new UpdateByQueryRethrottleDescriptor(taskId)), cancellationToken); | ||
|
||
/// <inheritdoc /> | ||
public Task<IListTasksResponse> UpdateByQueryRethrottleAsync(IUpdateByQueryRethrottleRequest request, | ||
CancellationToken cancellationToken = default(CancellationToken) | ||
) => | ||
Dispatcher.DispatchAsync<IUpdateByQueryRethrottleRequest, UpdateByQueryRethrottleRequestParameters, ListTasksResponse, IListTasksResponse>( | ||
request, | ||
cancellationToken, | ||
(p, d, c) => LowLevelDispatch.UpdateByQueryRethrottleDispatchAsync<ListTasksResponse>(p, c) | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Nest/Document/Multiple/UpdateByQueryRethrottle/UpdateByQueryRethrottleRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace Nest | ||
{ | ||
public partial interface IUpdateByQueryRethrottleRequest | ||
{ | ||
} | ||
|
||
public partial class UpdateByQueryRethrottleRequest: IUpdateByQueryRethrottleRequest | ||
{ | ||
} | ||
|
||
public partial class UpdateByQueryRethrottleDescriptor : IUpdateByQueryRethrottleRequest | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/Tests/Tests/Document/Multiple/UpdateByQueryRethrottle/UpdateByQueryRethrottleApiTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using System; | ||
using System.Linq; | ||
using Elasticsearch.Net; | ||
using FluentAssertions; | ||
using Nest; | ||
using Tests.Document.Multiple.Reindex; | ||
using Tests.Domain; | ||
using Tests.Framework; | ||
using Tests.Framework.Integration; | ||
using Tests.Core.Extensions; | ||
|
||
namespace Tests.Document.Multiple.UpdateByQueryRethrottle | ||
{ | ||
public class UpdateByQueryRethrottleApiTests | ||
: ApiIntegrationTestBase<ReindexCluster, IListTasksResponse, IUpdateByQueryRethrottleRequest, | ||
UpdateByQueryRethrottleDescriptor, UpdateByQueryRethrottleRequest> | ||
{ | ||
protected const string TaskIdKey = "taskId"; | ||
|
||
public UpdateByQueryRethrottleApiTests(ReindexCluster cluster, EndpointUsage usage) : base(cluster, usage) { } | ||
|
||
protected override bool ExpectIsValid => true; | ||
protected override object ExpectJson => null; | ||
protected override int ExpectStatusCode => 200; | ||
|
||
protected override Func<UpdateByQueryRethrottleDescriptor, IUpdateByQueryRethrottleRequest> Fluent => d => d | ||
.RequestsPerSecond(-1); | ||
|
||
protected override HttpMethod HttpMethod => HttpMethod.POST; | ||
|
||
protected override UpdateByQueryRethrottleRequest Initializer => new UpdateByQueryRethrottleRequest(TaskId) | ||
{ | ||
RequestsPerSecond = -1 | ||
}; | ||
|
||
protected override bool SupportsDeserialization => false; | ||
protected TaskId TaskId => RanIntegrationSetup ? ExtendedValue<TaskId>(TaskIdKey) : "foo:1"; | ||
|
||
protected override string UrlPath => $"/_update_by_query/{TaskId.NodeId}%3A{TaskId.TaskNumber}/_rethrottle?requests_per_second=-1"; | ||
|
||
protected override UpdateByQueryRethrottleDescriptor NewDescriptor() => new UpdateByQueryRethrottleDescriptor(TaskId); | ||
|
||
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values) | ||
{ | ||
foreach (var callUniqueValue in values) | ||
{ | ||
client.IndexMany(Project.Projects, callUniqueValue.Value); | ||
client.Refresh(callUniqueValue.Value); | ||
} | ||
} | ||
|
||
protected override LazyResponses ClientUsage() => Calls( | ||
(client, f) => client.UpdateByQueryRethrottle(TaskId, f), | ||
(client, f) => client.UpdateByQueryRethrottleAsync(TaskId, f), | ||
(client, r) => client.UpdateByQueryRethrottle(r), | ||
(client, r) => client.UpdateByQueryRethrottleAsync(r) | ||
); | ||
|
||
protected override void OnBeforeCall(IElasticClient client) | ||
{ | ||
client.IndexMany(Project.Projects, CallIsolatedValue); | ||
client.Refresh(CallIsolatedValue); | ||
|
||
var updateByQuery = client.UpdateByQuery<Project>(u => u | ||
.Index(CallIsolatedValue) | ||
.Conflicts(Conflicts.Proceed) | ||
.Query(q => q.MatchAll()) | ||
.Script(s => s.Source("ctx._source.numberOfCommits+=10")) | ||
.Refresh() | ||
.RequestsPerSecond(1) | ||
.WaitForCompletion(false) | ||
); | ||
|
||
updateByQuery.ShouldBeValid(); | ||
ExtendedValue(TaskIdKey, updateByQuery.Task); | ||
} | ||
|
||
protected override void ExpectResponse(IListTasksResponse response) | ||
{ | ||
response.ShouldBeValid(); | ||
|
||
response.Nodes.Should().NotBeEmpty().And.HaveCount(1); | ||
var node = response.Nodes.First().Value; | ||
|
||
node.Name.Should().NotBeNullOrEmpty(); | ||
node.TransportAddress.Should().NotBeNullOrEmpty(); | ||
node.Host.Should().NotBeNullOrEmpty(); | ||
node.Ip.Should().NotBeNullOrEmpty(); | ||
node.Roles.Should().NotBeEmpty(); | ||
node.Attributes.Should().NotBeEmpty(); | ||
|
||
node.Tasks.Should().NotBeEmpty().And.HaveCount(1); | ||
node.Tasks.First().Key.Should().Be(TaskId); | ||
|
||
var task = node.Tasks.First().Value; | ||
|
||
task.Node.Should().NotBeNullOrEmpty().And.Be(TaskId.NodeId); | ||
task.Id.Should().Be(TaskId.TaskNumber); | ||
task.Type.Should().NotBeNullOrEmpty(); | ||
task.Action.Should().NotBeNullOrEmpty(); | ||
|
||
task.Status.RequestsPerSecond.Should().Be(-1); | ||
|
||
task.StartTimeInMilliseconds.Should().BeGreaterThan(0); | ||
task.RunningTimeInNanoSeconds.Should().BeGreaterThan(0); | ||
task.Cancellable.Should().BeTrue(); | ||
} | ||
} | ||
} |
Oops, something went wrong.