UNPKG

ductile

Version:

Elasticsearch Bulk Loader

71 lines (68 loc) 2.57 kB
// Generated by CoffeeScript 1.11.1 (function() { module.exports = function(client) { return function(bulk, callback) { return bulk.reduce(function(p, c) { return p.then(function() { var number_of_replicas, number_of_shards, putsettings, ref, ref1, ref2, t; t = c.settings; ref2 = (ref = (ref1 = t._settings) != null ? ref1.index : void 0) != null ? ref : {}, number_of_replicas = ref2.number_of_replicas, number_of_shards = ref2.number_of_shards; if (t._settings.index) { delete t._settings.index.number_of_replicas; delete t._settings.index.number_of_shards; } putsettings = function() { var attempt; attempt = function() { return (t._settings.analysis ? client.indices.close({ index: t._index }) : Promise.resolve()).then(function() { return client.indices.putSettings({ index: t._index, body: t._settings }); }).then(function(res) { return (t._settings.analysis ? client.indices.open({ index: t._index }) : Promise.resolve()).then(function() { return res; }); })["catch"](function(err) { var ref3, ref4; if (((ref3 = err.body) != null ? (ref4 = ref3.error) != null ? ref4.type : void 0 : void 0) === 'index_primary_shard_not_allocated_exception') { return attempt(); } else { throw err; } }); }; return attempt(); }; return putsettings()["catch"](function(err) { var opts; if (err.status === 404) { opts = { index: t._index, body: {} }; if (number_of_replicas != null) { opts.body.number_of_replicas = number_of_replicas; } if (number_of_shards != null) { opts.body.number_of_shards = number_of_shards; } return client.indices.create(opts).then(putsettings); } else { throw err; } }); }); }, Promise.resolve()).then(function() { return callback(null, {}); })["catch"](function(err) { return callback(err); }); }; }; }).call(this); //# sourceMappingURL=write-settings.js.map