ductile
Version:
Elasticsearch Bulk Loader
55 lines (47 loc) • 1.28 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({
template: 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.getTemplate(opts).then(function(v) {
var name, results, template;
results = [];
for (name in v) {
template = v[name];
results.push({
_name: name,
_template: template
});
}
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=template.js.map