elasticsearch - Elasticsearch - buckets_path 聚合项
问题描述
我正在尝试对术语进行 AVG 计数(count_bucket),但出现错误:
"buckets_path must reference either a number value or a single value numeric metric aggregation, got: [Bucket] at aggregation [count_bucket]"
这是我的查询:count_bucket 是 count term agg 并且我想要这个的平均值。
{
"size": 0,
track_total_hits: true,
"query": {
"bool": {
"must": queries,
"must_not": {
"exists": {
"field": supress
}
}
}
},
"aggs": {
"count_bucket": {
"terms": {
"field": field,
"size": 500,
"order": {
"_key": "desc"
}
}
},
"avg_count": {
"avg_bucket": {
"buckets_path": "count_bucket"
}
}
}
}
解决方案
错误消息中描述了该问题:术语聚合不返回单个值,这与其他聚合(例如sum
or )不同value_count
。因此,您无法avg_bucket
对这些存储桶执行聚合。
一个好的解决方案是在每个存储桶上使用value_count
聚合来返回单个值,然后您可以在该值上进行avg_bucket
聚合:
这是它的外观:
{
"query": {
"bool": {
"must": queries,
"must_not": {
"exists": {
"field": supress
}
}
}
},
"aggs": {
"count_bucket": {
"terms": {
"field": field,
"size": 500,
"order": {
"_key": "desc"
}
},
"aggs": {
"docs_count": {
"value_count": {
"field": field
}
}
}
},
"avg_count": {
"avg_bucket": {
"buckets_path": "count_bucket>docs_count"
}
}
}
}
推荐阅读
- .htaccess - .htaccess 基于浏览器语言的重写只适用一次
- jquery - 在移动设备上禁用垂直滚动(但不是水平滚动)
- jquery - 如何在 Outlook 电子邮件中插入 HTML 和 CSS 网页?
- ionic3 - 如何在ionic3中对齐单选按钮和标签
- google-app-engine - 在 Google 应用引擎 Web 应用程序上,除了 Google 身份平台之外,还有哪些身份验证选项?
- youtube-api - 如何通过 youtube id 获取 youtube 字幕
- powershell - 在 SQL 中插入日期
- java - Jax-RS:从头部调用响应中提取特定标头?
- java - 使用逗号分隔和多个参数创建 Rest url
- python - 如何使用 Python 获取 Excel 工作簿的路径