Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rethrottle support to reindex api #319

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/elastomer_client/client/reindex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def reindex(body, params = {})
response.body
end

def rethrottle(task_id, params = {})
response = client.post "/_reindex/#{task_id}/_rethrottle", params.merge(params, action: "rethrottle", rest_api: "reindex")
response.body
end

end
end
end
26 changes: 25 additions & 1 deletion test/client/reindex_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@
assert_equal "Book 1", doc["_source"]["title"]
end

it "successfully rethrottles a reindex task" do
reindex = $client.reindex
body = {
source: { index: @source_index.name },
dest: { index: @dest_index.name }
}
response = reindex.reindex(body, requests_per_second: 0.01, wait_for_completion: false)
task_id = response["task"]

reindex.rethrottle(task_id, requests_per_second: 1)

tasks = $client.tasks
node_id = task_id.split(":").first
task_id = task_id.split(":").last.to_i

# wait for the task to complete
tasks.wait_by_id(node_id, task_id, "30s")

# Verify that the document has been reindexed
doc = @dest_index.docs.get(id: 1, type: "book")

assert_equal "Book 1", doc["_source"]["title"]
end

it "creates a new index when the destination index does not exist" do
reindex = $client.reindex
body = {
Expand All @@ -69,7 +93,7 @@
}

exception = assert_raises(ElastomerClient::Client::RequestError) do
response = reindex.reindex(body)
reindex.reindex(body)
end
assert_equal(404, exception.status)
end
Expand Down
Loading