2
2
3
3
var cli = require ( 'commander' ) ,
4
4
elasticsearch = require ( 'elasticsearch' ) ,
5
- async = require ( 'async' ) ,
6
5
cluster = require ( 'cluster' ) ,
7
6
moment = require ( 'moment' ) ,
8
7
_ = require ( 'underscore' ) ,
@@ -97,6 +96,7 @@ if (cluster.isMaster) {
97
96
}
98
97
} ) ;
99
98
} else {
99
+ var worker_arg = null ;
100
100
var range = null ;
101
101
var shard_name = '' ;
102
102
@@ -108,8 +108,21 @@ if (cluster.isMaster) {
108
108
109
109
var from_uri = new URI ( cli . from ) ,
110
110
to_uri = new URI ( cli . to ) ,
111
- from_client = new elasticsearch . Client ( { host : cli . from . replace ( new RegExp ( escapeRegExp ( from_uri . path ( ) ) + '.*' ) , '' ) , requestTimeout : cli . request_timeout , apiVersion : cli . api_ver } ) ,
112
- to_client = new elasticsearch . Client ( { host : cli . to . replace ( new RegExp ( escapeRegExp ( to_uri . path ( ) ) + '.*' ) , '' ) , requestTimeout : cli . request_timeout , apiVersion : cli . api_ver } ) ,
111
+ from_host = cli . from . replace ( new RegExp ( escapeRegExp ( from_uri . path ( ) ) + '.*' ) , '' ) ,
112
+ to_host = cli . to . replace ( new RegExp ( escapeRegExp ( to_uri . path ( ) ) + '.*' ) , '' ) ;
113
+
114
+ // If no path was supplied, URIjs will always return '/' from `MyURI.path()`
115
+ // We should strip the trailing slash if present and provide the rest of
116
+ // the host string to the client.
117
+ if ( from_uri . path ( ) === '/' ) {
118
+ from_host = cli . from . replace ( / \/ $ / , '' ) ;
119
+ }
120
+ if ( to_uri . path ( ) === '/' ) {
121
+ to_host = cli . to . replace ( / \/ $ / , '' ) ;
122
+ }
123
+
124
+ var from_client = new elasticsearch . Client ( { host : from_host , requestTimeout : cli . request_timeout , apiVersion : cli . api_ver } ) ,
125
+ to_client = new elasticsearch . Client ( { host : to_host , requestTimeout : cli . request_timeout , apiVersion : cli . api_ver } ) ,
113
126
from_path = ( function ( ) { var tmp = from_uri . path ( ) . split ( '/' ) ; return { index :tmp [ 1 ] , type :tmp [ 2 ] } ; } ) ( ) ,
114
127
to_path = ( function ( ) { var tmp = to_uri . path ( ) . split ( '/' ) ; return { index :tmp [ 1 ] , type :tmp [ 2 ] } ; } ) ( ) ,
115
128
processed_total = 0 ,
@@ -158,7 +171,7 @@ if (cluster.isMaster) {
158
171
console . log ( 'No documents can be found!' ) ;
159
172
return process . exit ( ) ;
160
173
}
161
- bar . total = cli . max_docs == - 1 ? res . hits . total : ( cli . max_docs > res . hits . total ? res . hits . total : cli . max_docs ) ;
174
+ bar . total = cli . max_docs === - 1 ? res . hits . total : ( cli . max_docs > res . hits . total ? res . hits . total : cli . max_docs ) ;
162
175
var docs = res . hits . hits ,
163
176
reindexMethod = cli . promise ? 'indexPromise' : 'index' ;
164
177
0 commit comments