UNPKG

567 Btext/coffeescriptView Raw
1
2
3module.exports = (client) -> (bulk, callback) ->
4 bulk.reduce (p, c) ->
5 p.then ->
6 t = c.mapping
7 putmapping = ->
8 client.indices.putMapping {index:t._index, type:t._type, body:t._mapping}
9 putmapping().catch (err) ->
10 if err.status == 404
11 client.indices.create {index:t._index}
12 .then putmapping
13 else
14 throw err
15 , Promise.resolve()
16 .then ->
17 callback null, {}
18 .catch (err) ->
19 callback err