-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.js
53 lines (47 loc) · 1.06 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
47
48
49
50
51
52
53
const cities = require('./cities.json');
const client = require('./config').client;
var bulk = [];
cities.forEach(city =>{
bulk.push({
index:{
_index:"cities",
_type:"cities_list",
}
});
bulk.push(city)
});
client.ping({
requestTimeout:30000
}, function(error) {
if(error) {
console.log('Server is down');
} else {
console.log('Server is running');
}
});
client.indices.create({
index: 'cities'
}, function(error, response, status) {
if (error) {
console.log(error);
} else {
console.log("created a new index", response);
}
});
// For deleting an index
// client.indices.delete({
// index: 'scotch.io-tutorial'
// }, function(error, response, status) {
// if (error) {
// console.log(error);
// } else {
// console.log("DELETED the index", response);
// }
// });
client.bulk({ body: bulk }, function (err) {
if(err) {
console.log("Failed Bulk operation".red, err)
} else {
console.log("Successfully imported", cities.length);
}
});