在kibana中,它可以通过发送请求字段的建议
{"field":"service"}
到
/api/kibana/suggestions/values/index-*
并且通过elasticsearch-js我可以使用聚合
await client.search({
index: "index-*",
body: {
query: {
bool: {
must: [{
range: {
"@timestamp": {
gte: "now-16m",
lte: "now-1m"
}
}
}, {
query_string: {
query: `beat.environment:${variables.environment}`
}
}]
}
},
aggs: {
resources: {
terms: {
field: "service",
size: 100
}
}
}
},
size: 0
});
以获得类似的结果,但我宁愿使用其内置的建议功能:
await client.search({
index: "index-*",
body: {
query: {
bool: {
must: [{
range: {
"@timestamp": {
gte: "now-16m",
lte: "now-1m"
}
}
}, {
query_string: {
query: `beat.environment:${variables.environment}`
}
}]
}
},
suggest: {
service: {
term : {
text: "",
field : "service"
}
}
}
},
size: 0
});
不幸的是,这失败了。