ductile
Version:
Elasticsearch Bulk Loader
86 lines (78 loc) • 2.2 kB
JavaScript
// Generated by CoffeeScript 1.11.1
(function() {
var jsonStream, mixin, through2, toBulk;
through2 = require('through2');
mixin = require('./mixin');
toBulk = function() {
return through2.obj(function(doc, enc, callback) {
this.push({
alias: doc
});
return callback();
});
};
jsonStream = function() {
return through2.obj(function(chunk, enc, callback) {
this.push(JSON.stringify(chunk) + "\n");
return callback();
});
};
module.exports = function(client, _opts) {
var exec, instream, opts, sink, stream;
opts = mixin(_opts);
instream = toBulk();
sink = instream.write.bind(instream);
exec = function() {
return client.indices.getAlias(opts).then(function(v) {
var aliases, index, results;
results = [];
for (index in v) {
aliases = v[index].aliases;
results.push(index);
}
return results;
}).then(function(indices) {
return Promise.all(indices.map(function(index) {
return client.indices.getAlias({
index: index
});
}));
}).then(function(vs) {
var _name, col, i, results;
col = {};
vs.map(function(v) {
var aliases, i, n, results;
results = [];
for (i in v) {
aliases = v[i].aliases;
results.push((function() {
var ref, results1;
results1 = [];
for (n in aliases) {
results1.push((col[n] = (ref = col[n]) != null ? ref : []).push(i));
}
return results1;
})());
}
return results;
});
results = [];
for (_name in col) {
i = col[_name];
results.push({
_name: _name,
_index: (i.length === 1 ? i[0] : i)
});
}
return results;
});
};
exec().then(function(docs) {
return docs.forEach(sink);
})["catch"](function(err) {
return stream.emit('error', err);
});
return stream = instream.pipe(jsonStream());
};
}).call(this);
//# sourceMappingURL=alias.js.map