Skip to content

Commit d0cd230

Browse files
committed
Handle pathless connections. (Fixes #8)
1 parent 2b32e90 commit d0cd230

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

.jshintrc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"curly": true, // true: Require {} for every new block or scope
3+
"eqeqeq": true, // true: Require triple equals (===) for comparison
4+
"immed": true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
5+
"latedef": true, // true: Require variables/functions to be defined before being used
6+
"newcap": true, // true: Require capitalization of all constructor functions e.g. `new F()`
7+
"noarg": true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
8+
"sub": true, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
9+
"undef": true, // true: Require all non-global variables to be declared (prevents global leaks)
10+
"boss": true, // true: Tolerate assignments where comparisons would be expected
11+
"eqnull": true, // true: Tolerate use of `== null`
12+
"expr": true, // true: Tolerate bare expressions
13+
"unused": "vars", // vars: Don't tolerate unused variables, but unused function params are OK
14+
"node": true,
15+
"globals": {
16+
"module": false,
17+
"require": false,
18+
"__dirname": false,
19+
"setTimeout": false,
20+
"console": false,
21+
"describe": false,
22+
"it": false,
23+
"beforeEach": false,
24+
"before": false,
25+
"afterEach": false,
26+
"after": false
27+
}
28+
}

bin/elasticsearch-reindex.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
var cli = require('commander'),
44
elasticsearch = require('elasticsearch'),
5-
async = require('async'),
65
cluster = require('cluster'),
76
moment = require('moment'),
87
_ = require('underscore'),
@@ -97,6 +96,7 @@ if (cluster.isMaster) {
9796
}
9897
});
9998
} else {
99+
var worker_arg = null;
100100
var range = null;
101101
var shard_name = '';
102102

@@ -108,8 +108,21 @@ if (cluster.isMaster) {
108108

109109
var from_uri = new URI(cli.from),
110110
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 }),
113126
from_path = (function() { var tmp = from_uri.path().split('/'); return { index:tmp[1], type:tmp[2]}; })(),
114127
to_path = (function() { var tmp = to_uri.path().split('/'); return { index:tmp[1], type:tmp[2]}; })(),
115128
processed_total = 0,
@@ -158,7 +171,7 @@ if (cluster.isMaster) {
158171
console.log('No documents can be found!');
159172
return process.exit();
160173
}
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);
162175
var docs = res.hits.hits,
163176
reindexMethod = cli.promise ? 'indexPromise' : 'index';
164177

0 commit comments

Comments
 (0)