1 |
|
2 | module.exports = (client) -> (bulk, callback) ->
|
3 | bulk.reduce (p, c) ->
|
4 | p.then ->
|
5 | t = c.alias
|
6 | putalias = -> client.indices.putAlias {name:t._name, index:t._index}
|
7 | putalias().catch (err) ->
|
8 | if err.status == 404
|
9 | client.indices.create {index:t._index}
|
10 | .then putalias
|
11 | else
|
12 | throw err
|
13 |
|
14 | , Promise.resolve()
|
15 | .then ->
|
16 | callback null, {}
|
17 | .catch (err) ->
|
18 | callback err
|