Skip to content

Commit 8d039fd

Browse files
committed
[EXT] Moved the :transform option for "Reindex" extension
Moved the `:transform` option from `:target` into the top level of Hash arguments -- this seems like a more natural way. Related: #270
1 parent 8dd5a04 commit 8d039fd

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

elasticsearch-extensions/lib/elasticsearch/extensions/reindex.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ def reindex(arguments={})
6868
#
6969
# reindex = Elasticsearch::Extensions::Reindex.new \
7070
# source: { index: 'test1', client: client },
71-
# target: { index: 'test2' },
72-
# transform: lambda { |doc| doc['_source']['category'].upcase! }
71+
# target: { index: 'test2', transform: lambda { |doc| doc['_source']['category'].upcase! } }
72+
#
7373
#
7474
# The reindexing process works by "scrolling" an index and sending
7575
# batches via the "Bulk" API to the target index/cluster
7676
#
7777
# @option arguments [String] :source The source index/cluster definition (*Required*)
7878
# @option arguments [String] :target The target index/cluster definition (*Required*)
79+
# @option arguments [Proc] :transform A block which will be executed for each document
7980
# @option arguments [Integer] :batch_size The size of the batch for scroll operation (Default: 1000)
8081
# @option arguments [String] :scroll The timeout for the scroll operation (Default: 5min)
8182
# @option arguments [Boolean] :refresh Whether to refresh the target index after
8283
# the operation is completed (Default: false)
83-
# @option arguments [Proc] :transform A block which will be executed for each document
8484
#
8585
# Be aware, that if you want to change the target index settings and/or mappings,
8686
# you have to do so in advance by using the "Indices Create" API.
@@ -137,7 +137,7 @@ def perform
137137
bulk = documents.map do |doc|
138138
doc['_index'] = arguments[:target][:index]
139139

140-
arguments[:target][:transform].call(doc) if arguments[:target][:transform]
140+
arguments[:transform].call(doc) if arguments[:transform]
141141

142142
doc['data'] = doc['_source']
143143
doc.delete('_score')

elasticsearch-extensions/test/reindex/integration/reindex_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class Elasticsearch::Extensions::ReindexIntegrationTest < Elasticsearch::Test::I
4343
should "transform documents with a lambda" do
4444
reindex = Elasticsearch::Extensions::Reindex.new \
4545
source: { index: 'test1', client: @client },
46-
target: { index: 'test2', transform: lambda { |d| d['_source']['category'].upcase! } },
46+
target: { index: 'test2' },
47+
transform: lambda { |d| d['_source']['category'].upcase! },
4748
refresh: true
4849

4950
result = reindex.perform

elasticsearch-extensions/test/reindex/unit/reindex_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ class Elasticsearch::Extensions::ReindexTest < Test::Unit::TestCase
8383
client = mock()
8484
subject = Elasticsearch::Extensions::Reindex.new \
8585
source: { index: 'foo', client: client },
86-
target: { index: 'bar', transform: lambda { |d| d['_source']['foo'].upcase!; d } }
86+
target: { index: 'bar' },
87+
transform: lambda { |d| d['_source']['foo'].upcase!; d }
8788

8889
client.expects(:search).returns({ '_scroll_id' => 'scroll_id_1' })
8990
client.expects(:scroll).returns(@default_response)

0 commit comments

Comments
 (0)