19
19
. option ( '-b, --bulk [value]' , 'bulk size for a thread' , 100 )
20
20
. option ( '-q, --query_size [value]' , 'query size for scroll' , 100 )
21
21
. option ( '-s, --scroll [value]' , 'default 1m' , '1m' )
22
+ . option ( '-i, --sniff_cluster [value]' , 'sniff the rest of the cluster upon initial connection and connection errors' , true )
22
23
. option ( '-o, --request_timeout [value]' , 'default 60000' , 60000 )
23
24
. option ( '-l, --log_path [value]' , 'default ./reindex.log' , './reindex.log' )
24
25
. option ( '-r, --trace' , 'default false' , false )
25
26
. option ( '-n, --max_docs [value]' , 'default -1 unlimited' , - 1 )
26
- . option ( '-v, --api_ver [value]' , 'default 1.5' , '1.5' )
27
+ . option ( '--from_ver [value]' , 'default 1.5' , '1.5' )
28
+ . option ( '--to_ver [value]' , 'default 1.5' , '1.5' )
27
29
. option ( '-p, --parent [value]' , 'if set, uses this field as parent field' , '' )
28
30
. option ( '-m, --promise [value]' , 'if set indexes expecting promises, default: false' , false )
29
31
. option ( '-z, --compress [value]' , 'if set, requests compression of data in transit' , false )
32
34
. option ( '-e, --region [value]' , 'AWS region' , false )
33
35
. parse ( process . argv ) ;
34
36
37
+ for ( var key in cli ) {
38
+ if ( cli . hasOwnProperty ( key ) ) {
39
+ if ( cli [ key ] === 'false' ) {
40
+ cli [ key ] = false ;
41
+ } else if ( cli [ key ] === 'true' ) {
42
+ cli [ key ] = true ;
43
+ }
44
+ }
45
+ }
46
+
35
47
var logger = bunyan . createLogger ( {
36
48
src : true ,
37
49
name : "elasticsearch-reindex" ,
@@ -147,7 +159,7 @@ if (cluster.isMaster) {
147
159
shard_name = cluster . worker . id ;
148
160
}
149
161
150
- function createClient ( uri ) {
162
+ function createClient ( uri , apiVersion ) {
151
163
if ( ! / \w + : \/ \/ / . test ( uri ) ) {
152
164
uri = 'http://' + uri ;
153
165
}
@@ -162,10 +174,10 @@ if (cluster.isMaster) {
162
174
163
175
var config = {
164
176
requestTimeout : cli . request_timeout ,
165
- apiVersion : cli . api_ver ,
177
+ apiVersion : apiVersion ,
166
178
suggestCompression : cli . compress ,
167
- sniffOnStart : true ,
168
- sniffOnConnectionFault : true
179
+ sniffOnStart : cli . sniff_cluster ,
180
+ sniffOnConnectionFault : cli . sniff_cluster
169
181
} ;
170
182
171
183
if ( cli . access_key && cli . secret_key && cli . region && / \. a m a z o n a w s \. / . test ( uri ) ) {
@@ -187,8 +199,8 @@ if (cluster.isMaster) {
187
199
throw new Error ( '"from" and "to" parameters are required' ) ;
188
200
}
189
201
190
- var from = createClient ( cli . from ) ;
191
- to = createClient ( cli . to ) ,
202
+ var from = createClient ( cli . from , cli . from_ver ) ;
203
+ to = createClient ( cli . to , cli . to_ver ) ,
192
204
processed_total = 0 ,
193
205
processed_failed = 0 ;
194
206
@@ -226,6 +238,9 @@ if (cluster.isMaster) {
226
238
227
239
from . client . search ( scan_options , function scroll_fetch ( err , res ) {
228
240
if ( err ) {
241
+ if ( err . message instanceof Error ) {
242
+ err = err . message ;
243
+ }
229
244
logger . fatal ( err ) ;
230
245
if ( err . message . indexOf ( 'parse' ) > - 1 ) {
231
246
throw new Error ( "Scroll body parsing error, query_size param is possibly too high." ) ;
0 commit comments