1 |
|
2 | (function() {
|
3 | module.exports = function(client) {
|
4 | return function(bulk, callback) {
|
5 | return bulk.reduce(function(p, c) {
|
6 | return p.then(function() {
|
7 | var putmapping, t;
|
8 | t = c.mapping;
|
9 | putmapping = function() {
|
10 | return client.indices.putMapping({
|
11 | index: t._index,
|
12 | type: t._type,
|
13 | body: t._mapping
|
14 | });
|
15 | };
|
16 | return putmapping()["catch"](function(err) {
|
17 | if (err.status === 404) {
|
18 | return client.indices.create({
|
19 | index: t._index
|
20 | }).then(putmapping);
|
21 | } else {
|
22 | throw err;
|
23 | }
|
24 | });
|
25 | });
|
26 | }, Promise.resolve()).then(function() {
|
27 | return callback(null, {});
|
28 | })["catch"](function(err) {
|
29 | return callback(err);
|
30 | });
|
31 | };
|
32 | };
|
33 |
|
34 | }).call(this);
|
35 |
|
36 |
|