UNPKG

ductile

Version:

Elasticsearch Bulk Loader

68 lines (59 loc) 1.67 kB
// Generated by CoffeeScript 1.11.1 (function() { var flatten, jsonStream, mixin, through2, toBulk; through2 = require('through2'); mixin = require('./mixin'); flatten = function(a) { return [].concat.apply([], a); }; toBulk = function() { return through2.obj(function(doc, enc, callback) { this.push({ mapping: 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.getMapping(opts).then(function(v) { var index, mapping, mappings, results, type; results = []; for (index in v) { mappings = v[index].mappings; results.push((function() { var results1; results1 = []; for (type in mappings) { mapping = mappings[type]; results1.push({ _index: index, _type: type, _mapping: mapping }); } return results1; })()); } return results; }).then(flatten); }; exec().then(function(docs) { return docs.forEach(sink); })["catch"](function(err) { return stream.emit('error', err); }); return stream = instream.pipe(jsonStream()); }; }).call(this); //# sourceMappingURL=mappings.js.map