-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_query.js
40 lines (33 loc) · 912 Bytes
/
test_query.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
var config = require('config');
var fs = require('fs');
const { Client } = require('@elastic/elasticsearch')
const client = new Client({
node: config.elasticsearch.node,
auth: {
apiKey: config.elasticsearch.api_key_encoded,
},
tls: {
ca: fs.readFileSync('./certs/http_ca.crt'),
rejectUnauthorized: false
}
})
async function main() {
try {
const result = await client.info();
console.log('Elasticsearch v' + result.version.number + ' is running...');
var searchQuery = "moops";
searchResults = await client.search({
index: config.elasticsearch.index,
query: {
match: {
text: searchQuery
}
},
size: 5
});
console.log(searchResults.hits.hits)
} catch (error) {
console.error(error);
}
}
main();