-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathdata.js
47 lines (39 loc) · 1.03 KB
/
data.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
const elasticsearch = require('elasticsearch');
const client = new elasticsearch.Client({
hosts: [ 'http://localhost:9200']
});
client.ping({
requestTimeout: 30000,
}, function(error) {
if (error) {
console.error('elasticsearch cluster is down!');
} else {
console.log('Everything is ok');
}
});
client.indices.create({
index: 'scotch.io-tutorial'
}, function(error, response, status) {
if (error) {
console.log(error);
} else {
console.log("created new index", response);
}
});
const cities = require('./cities.json');
var bulk = [];
cities.forEach(city =>{
bulk.push({index:{
_index:"scotch.io-tutorial",
_type:"cities_list",
}
})
bulk.push(city)
})
client.bulk({body:bulk}, function( err, response ){
if( err ){
console.log("Failed Bulk operation".red, err)
} else {
console.log("Successfully imported %s".green, bulk.length);
}
});