-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelastic.js
74 lines (61 loc) · 1.29 KB
/
elastic.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const elasticsearch = require('elasticsearch');
const elasticClient = new elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
elasticClient.ping({
requestTimeout: 30000,
}, (error) => {
if (error) {
console.error('elasticsearch cluster is down!');
}
else {
console.log('Everything is ok');
}
});
elasticClient.indices.create({
index: 'blog'
}, (err, resp, status) => {
if (err) {
console.log(err);
}
else {
console.log("create", resp);
}
});
elasticClient.index({
index: 'blog',
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.",
}
}, function(err, resp, status) {
console.log(resp);
});
elasticClient.search({
index: 'blog',
type: 'posts',
q: 'PostName:Node.js'
}).then(function(resp) {
console.log(resp);
}, function(err) {
console.trace(err.message);
});
elasticClient.search({
index: 'blog',
type: 'posts',
body: {
query: {
match: {
"PostName": 'Node.js'
}
}
}
}).then(function(resp) {
console.log(resp);
}, function(err) {
console.trace(err.message);
});