Skip to content

Commit 1cf5fb9

Browse files
committed
[API] Added the "Reindex" API
Related: elastic/elasticsearch#15201
1 parent 164d6dc commit 1cf5fb9

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
module Elasticsearch
2+
module API
3+
module Actions
4+
5+
# Copy documents from one index to another, potentially changing
6+
# its settings, mappings and the documents itself.
7+
#
8+
# @example Copy documents into a different index
9+
#
10+
# client.reindex body: { source: { index: 'test1' }, dest: { index: 'test2' } }
11+
#
12+
# @example Limit the copied documents with a query
13+
#
14+
# client.reindex body: {
15+
# source: {
16+
# index: 'test1',
17+
# query: { terms: { category: ['one', 'two'] } }
18+
# },
19+
# dest: {
20+
# index: 'test2'
21+
# }
22+
# }
23+
#
24+
# @example Remove a field from reindexed documents
25+
#
26+
# client.reindex body: {
27+
# source: {
28+
# index: 'test1'
29+
# },
30+
# dest: {
31+
# index: 'test3'
32+
# },
33+
# script: {
34+
# inline: 'ctx._source.remove("category")'
35+
# }
36+
# }
37+
#
38+
# @option arguments [Hash] :body The definition of the operation (source index, target index, ...)
39+
# (*Required*)
40+
# @option arguments [Boolean] :refresh Whether the affected indexes should be refreshed
41+
# @option arguments [Time] :timeout Time each individual bulk request should wait for shards
42+
# that are unavailable. (Default: 1m)
43+
# @option arguments [String] :consistency Explicit write consistency setting for the operation
44+
# (Options: one, quorum, all)
45+
# @option arguments [Boolean] :wait_for_completion Whether the request should block and wait until
46+
# the operation has completed
47+
# @option arguments [Float] :requests_per_second The throttling for this request in sub-requests per second.
48+
# 0 means set no throttling (default)
49+
#
50+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html
51+
#
52+
def reindex(arguments={})
53+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
54+
valid_params = [
55+
:refresh,
56+
:timeout,
57+
:consistency,
58+
:wait_for_completion,
59+
:requests_per_second ]
60+
method = 'POST'
61+
path = "_reindex"
62+
params = Utils.__validate_and_extract_params arguments, valid_params
63+
body = arguments[:body]
64+
65+
perform_request(method, path, params, body).body
66+
end
67+
end
68+
end
69+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'test_helper'
2+
3+
module Elasticsearch
4+
module Test
5+
class ReindexTest < ::Test::Unit::TestCase
6+
7+
context "Reindex" do
8+
subject { FakeClient.new }
9+
10+
should "perform correct request" do
11+
subject.expects(:perform_request).with do |method, url, params, body|
12+
assert_equal 'POST', method
13+
assert_equal '_reindex', url
14+
assert_equal Hash.new, params
15+
assert_equal Hash.new, body
16+
true
17+
end.returns(FakeResponse.new)
18+
19+
subject.reindex :body => {}
20+
end
21+
22+
end
23+
24+
end
25+
end
26+
end

0 commit comments

Comments
 (0)