ductile
Version:
Elasticsearch Bulk Loader
40 lines (34 loc) • 1.08 kB
JavaScript
// Generated by CoffeeScript 1.11.1
(function() {
var OPERS, mixin;
mixin = require('./mixin');
OPERS = require('./opers');
module.exports = function(client, _opts) {
return function(bulk, callback) {
var opts;
opts = mixin(_opts, {
body: bulk
});
return client.bulk(opts).then(function(res) {
var oper, reason, ref, ref1, ref2;
if (res != null ? res.errors : void 0) {
oper = OPERS.find(function(oper) {
var ref;
return (ref = res.items[0]) != null ? ref[oper] : void 0;
});
reason = (ref = res.items[0]) != null ? (ref1 = ref[oper]) != null ? (ref2 = ref1.error) != null ? ref2.reason : void 0 : void 0 : void 0;
if (reason) {
return callback(new Error(reason));
} else {
return callback(res);
}
} else {
return callback(null, res);
}
})["catch"](function(err) {
return callback(err);
});
};
};
}).call(this);
//# sourceMappingURL=write-bulk.js.map