我正在使用ElasticSearch v5.我正在尝试在Elasticsearch analytics percent中执行类似的操作,其中我有一个术语聚合,我想计算一个百分比,它是每个存储桶中所有存储桶总数的值.这是我的要求:
{
"query": {
"match_all": {}
},
"aggs": {
"periods": {
"terms": {
"field": "periods",
"size": 3
},
"aggs": {
"balance": {
"sum": {
"field": "balance"
}
}
}
},
"total_balance": {
"sum_bucket": {
"buckets_path": "periods>balance"
}
}
}
Run Code Online (Sandbox Code Playgroud)
}
我得到的结果如下:
{
"aggregations": {
"periods": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 1018940846,
"buckets": [
{
"key": 1177977600000,
"doc_count": 11615418,
"balance": {
"value": 2492032741768.1616
}
},
{
"key": 1185926400000,
"doc_count": 11592425,
"balance": {
"value": 2575365325406.6533
}
},
{
"key": 1175385600000,
"doc_count": 11477402,
"balance": {
"value": 2456256695380.8306
}
}
]
},
"total_balance": {
"value": 7523654762555.645
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何从ElasticSearch计算存储桶中每个项目的"balance"/"total_balance"?我在桶(句点)级别尝试了桶脚本聚合,但是我无法将我的buckets_path设置为total_balance.这篇文章https://discuss.elastic.co/t/combining-two-aggregations-to-get-term-percentage/22201讨论了使用重要术语聚合,但我需要计算使用特定字段,而不是doc_count.我知道我可以在客户端进行简单的计算,但是如果可能的话,我想在ElasticSearch中一起完成这个.
不,你不能那样做。当我写这篇文章时,我们已经使用了 6.1 版本。
根据 https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html#buckets-path-syntax,只有两种主要类型的聚合管道:父级和同级。
因此,为了total_balance从周期存储桶内引用聚合,我们应该能够从buckets_path属性引用“uncle”聚合,但这是不可能的。
| 归档时间: |
|
| 查看次数: |
2899 次 |
| 最近记录: |