-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotherImport.js
49 lines (44 loc) · 1.03 KB
/
otherImport.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var elasticsearch = require('elasticsearch');
var fs = require('fs');
var esClient = require('./elastic-client.js');
const bulkIndex = function bulkIndex(index, type, data) {
var bulkBody = [];
// data.forEach(item => {
// bulkBody.push({
// index: {
// _index: index,
// _type: type,
// _id: item.id
// }
// });
console.log(data);
bulkBody.push({
index: {
_index: index,
_type: type,
_id: '26532195'
}
});
bulkBody.push(data);
console.log(bulkBody);
esClient.bulk({body: bulkBody})
.then(response => {
var errorCount = 0;
response.items.forEach(item => {
if (item.index && item.index.error) {
console.log(++errorCount, item.index.error);
}
});
console.log(
`Successfully indexed ${data.length - errorCount}
out of ${data.length} items`
);
})
.catch(console.err);
};
fs.readFile('single_filtered_user.json', 'utf-8', function(err, data) {
if(err) {
console.log(err);
}
bulkIndex('users', 'user', JSON.parse(data));
});