UNPKG

1.06 kBtext/coffeescriptView Raw
1through2 = require 'through2'
2mixin = require './mixin'
3
4
5toBulk = -> through2.obj (doc, enc, callback) ->
6 this.push settings:doc
7 callback()
8
9
10jsonStream = -> through2.obj (chunk, enc, callback) ->
11 this.push(JSON.stringify(chunk) + "\n")
12 callback()
13
14
15module.exports = (client, _opts) ->
16
17 opts = mixin _opts
18
19 instream = toBulk()
20 sink = instream.write.bind instream
21
22 exec = ->
23 client.indices.getSettings(opts).then (v) ->
24 for index, {settings} of v
25 delete settings.index.uuid
26 delete settings.index.version
27 delete settings.index.creation_date
28 # analysis is inside index for some reason
29 if settings.index?.analysis
30 settings.analysis = settings.index.analysis
31 delete settings.index.analysis
32 {_index:index, _settings:settings}
33
34 exec().then (docs) ->
35 docs.forEach sink
36 .catch (err) ->
37 stream.emit 'error', err
38
39 stream = instream.pipe jsonStream()