UNPKG

821 Btext/coffeescriptView Raw
1through2 = require 'through2'
2mixin = require './mixin'
3
4
5flatten = (a) -> [].concat.apply [], a
6
7
8toBulk = -> through2.obj (doc, enc, callback) ->
9 this.push mapping:doc
10 callback()
11
12
13jsonStream = -> through2.obj (chunk, enc, callback) ->
14 this.push(JSON.stringify(chunk) + "\n")
15 callback()
16
17
18module.exports = (client, _opts) ->
19
20 opts = mixin _opts
21
22 instream = toBulk()
23 sink = instream.write.bind instream
24
25 exec = ->
26 client.indices.getMapping(opts).then (v) ->
27 for index, {mappings} of v
28 for type, mapping of mappings
29 {_index:index, _type:type, _mapping:mapping}
30 .then flatten
31
32 exec().then (docs) ->
33 docs.forEach sink
34 .catch (err) ->
35 stream.emit 'error', err
36
37 stream = instream.pipe jsonStream()