forked from rauniksingh/dCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesSetup.js
More file actions
60 lines (50 loc) · 1.43 KB
/
esSetup.js
File metadata and controls
60 lines (50 loc) · 1.43 KB
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
54
55
56
57
58
59
60
const elasticsearch = require('elasticsearch');
// const esClient = new elasticsearch.Client({
// host: ['127.0.0.1:9200'],
// log: 'error'
// });
// esClient.ping({
// requestTimeout: 30000,
// }, (error) => {
// if (error) {
// console.error('Elasticsearch cluster is down!');
// } else {
// console.log('Everything is ok');
// }
// });
let elasticClient;
module.exports.getElasticInstance = () => {
if (elasticClient)
return elasticClient;
elasticClient = new elasticsearch.Client({
host: 'localhost:9200'
});
return elasticClient;
};
//----Create new index
// esClient.indices.create({ index: 'thread' }, (err, resp, status) => {
// if (err) console.log(err);
// else console.log("create", resp);
// });
//----Adding document to index
// esClient.index({
// index: 'thread',
// id: '1',
// type: 'posts',
// body: {
// "PostName": "Integrating Elasticsearch Into Your Node.js Application",
// "PostType": "Tutorial",
// "PostBody": "This is the text of our tutorial about using Elasticsearch in your Node.js application.",
// }
// }, (err, resp, status) => {
// console.log(resp);
// });
// esClient.search({
// index: 'blog',
// type: 'posts',
// q: 'PostType:*to*'
// }).then(function(resp) {
// console.log('----->', resp.hits.hits);
// }, function(err) {
// console.trace(err.message);
// });