Skip to content

Commit f2d5777

Browse files
committed
add rethrottle support to reindex api
1 parent 324f0a9 commit f2d5777

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/elastomer_client/client/reindex.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ def reindex(body, params = {})
2424
response.body
2525
end
2626

27+
def rethrottle(task_id, params = {})
28+
response = client.post "/_reindex/#{task_id}/_rethrottle", params.merge(params, action: "rethrottle", rest_api: "reindex")
29+
response.body
30+
end
31+
2732
end
2833
end
2934
end

test/client/reindex_test.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,30 @@
4949
assert_equal "Book 1", doc["_source"]["title"]
5050
end
5151

52+
it "successfully rethrottles a reindex task" do
53+
reindex = $client.reindex
54+
body = {
55+
source: { index: @source_index.name },
56+
dest: { index: @dest_index.name }
57+
}
58+
response = reindex.reindex(body, requests_per_second: 0.01, wait_for_completion: false)
59+
task_id = response["task"]
60+
61+
reindex.rethrottle(task_id, requests_per_second: 1)
62+
63+
tasks = $client.tasks
64+
node_id = task_id.split(":").first
65+
task_id = task_id.split(":").last.to_i
66+
67+
# wait for the task to complete
68+
tasks.wait_by_id(node_id, task_id, "30s")
69+
70+
# Verify that the document has been reindexed
71+
doc = @dest_index.docs.get(id: 1, type: "book")
72+
73+
assert_equal "Book 1", doc["_source"]["title"]
74+
end
75+
5276
it "creates a new index when the destination index does not exist" do
5377
reindex = $client.reindex
5478
body = {
@@ -69,7 +93,7 @@
6993
}
7094

7195
exception = assert_raises(ElastomerClient::Client::RequestError) do
72-
response = reindex.reindex(body)
96+
reindex.reindex(body)
7397
end
7498
assert_equal(404, exception.status)
7599
end

0 commit comments

Comments
 (0)