-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (28 loc) · 722 Bytes
/
index.js
File metadata and controls
34 lines (28 loc) · 722 Bytes
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
const elasticsearch = require('elasticsearch');
const elastic = {
_client: {},
login: (host) => {
elastic._client = new elasticsearch.Client({
host: host,
log: 'trace',
maxRetries: 10
});
return elastic._client;
},
createIndex: (indexName, mapping) => {
elastic._client.indices.create({
index: indexName,
body: mapping
});
},
insert: (index, data) => {
elastic._client.index({
index: index,
type: 'doc',
body: JSON.stringify(data)
}, function (err, res, status) {
console.log(res);
});
}
};
module.exports = elastic;