我已经有各种各样的查询来收集数据并将其显示在Kibana仪表板中。现在,我想从结果数据中获取唯一值。我该如何编写查询DSL。
基本上,我想为contextMap.connectionid字段获取唯一值。有没有办法使用类似于此示例的方法来实现这一目标?
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "app",
"query": {
"bool": {
"must": [
{
"match": {
"app.key": "contextMap.connectionid"
}
}
]
}
}
}
}
]
}
}
}
您可以在汇总的帮助下计算不重复计数。因此,您的搜索查询是:
搜索查询:
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "app",
"query": {
"bool": {
"must": [
{
"match": {
"app.key": "contextMap.connectionid"
}
}
]
}
}
}
}
]
}
},
"aggs": {
"uniqueconnectionId": {
"terms": {
"field": "contextMap.connectionid.keyword"
}
}
}
}
您可以在这里参考以计算字段https://discuss.elastic.co/t/get-distinct-values-from-a-field-in-elasticsearch/99783的不同值