-
Notifications
You must be signed in to change notification settings - Fork 9
/
aggregation.js
42 lines (36 loc) · 840 Bytes
/
aggregation.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
const esClient = require('./client');
const searchDoc = async function(indexName, mappingType, payload){
return await esClient.search({
index: indexName,
type: mappingType,
body: payload
});
}
module.exports = searchDoc;
/**
* Example
*/
async function test(){
const body = {
query: {
match: {
"title": "Learn"
}
},
aggs: {
tags: {
terms: {
field: 'tags'
}
}
}
}
try {
const resp = await searchDoc('blog', 'test', body);
console.log(JSON.stringify(resp));
} catch (e) {
console.log(e);
}
}
// test();
// More details here https://www.elastic.co/guide/en/elasticsearch/reference/current/full-text-queries.html