1 |
|
2 | (function() {
|
3 | var flatten, jsonStream, mixin, through2, toBulk;
|
4 |
|
5 | through2 = require('through2');
|
6 |
|
7 | mixin = require('./mixin');
|
8 |
|
9 | flatten = function(a) {
|
10 | return [].concat.apply([], a);
|
11 | };
|
12 |
|
13 | toBulk = function() {
|
14 | return through2.obj(function(doc, enc, callback) {
|
15 | this.push({
|
16 | mapping: doc
|
17 | });
|
18 | return callback();
|
19 | });
|
20 | };
|
21 |
|
22 | jsonStream = function() {
|
23 | return through2.obj(function(chunk, enc, callback) {
|
24 | this.push(JSON.stringify(chunk) + "\n");
|
25 | return callback();
|
26 | });
|
27 | };
|
28 |
|
29 | module.exports = function(client, _opts) {
|
30 | var exec, instream, opts, sink, stream;
|
31 | opts = mixin(_opts);
|
32 | instream = toBulk();
|
33 | sink = instream.write.bind(instream);
|
34 | exec = function() {
|
35 | return client.indices.getMapping(opts).then(function(v) {
|
36 | var index, mapping, mappings, results, type;
|
37 | results = [];
|
38 | for (index in v) {
|
39 | mappings = v[index].mappings;
|
40 | results.push((function() {
|
41 | var results1;
|
42 | results1 = [];
|
43 | for (type in mappings) {
|
44 | mapping = mappings[type];
|
45 | results1.push({
|
46 | _index: index,
|
47 | _type: type,
|
48 | _mapping: mapping
|
49 | });
|
50 | }
|
51 | return results1;
|
52 | })());
|
53 | }
|
54 | return results;
|
55 | }).then(flatten);
|
56 | };
|
57 | exec().then(function(docs) {
|
58 | return docs.forEach(sink);
|
59 | })["catch"](function(err) {
|
60 | return stream.emit('error', err);
|
61 | });
|
62 | return stream = instream.pipe(jsonStream());
|
63 | };
|
64 |
|
65 | }).call(this);
|
66 |
|
67 |
|