Skip to content
This repository was archived by the owner on Mar 25, 2026. It is now read-only.

Commit 557ad92

Browse files
committed
ES 7x
1 parent 470b26b commit 557ad92

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "elasticbulk",
3-
"version": "1.0.24",
3+
"version": "1.0.26",
44
"description": "Add data in bulk to ItemsAPI or Elasticsearch. It supports data streaming from PostgreSQL or filesystem",
55
"main": "lib.js",
66
"scripts": {

src/elasticitems7x.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ module.exports.import = function(data, options, schema) {
2929
var elastic = new elasticsearch.Client({
3030
host: options.host,
3131
defer: function () {
32-
return Promise.defer();
32+
var resolve, reject;
33+
var promise = new Promise(function() {
34+
resolve = arguments[0];
35+
reject = arguments[1];
36+
});
37+
return {
38+
resolve: resolve,
39+
reject: reject,
40+
promise: promise
41+
};
3342
}
3443
});
3544

@@ -128,16 +137,15 @@ module.exports.addItemsStream = function(elastic, stream, options) {
128137

129138
module.exports.addBulkItems = function(elastic, items, options) {
130139

131-
var body = [];
132-
for (var i = 0 ; i < items.length ; ++i) {
133-
var o = { index: { _id: items[i] ? items[i]._id : undefined } };
134-
body.push(o);
135-
body.push(items[i]);
136-
}
140+
const body = items.flatMap(doc => [{
141+
index: {
142+
_index: options.index,
143+
_id: doc.id
144+
}
145+
}, doc])
137146

138147
return elastic.bulk({
139148
index: options.index,
140-
//type: options.type,
141149
body: body
142150
})
143151
.then(v => {

0 commit comments

Comments
 (0)