gpt4 book ai didi

elasticsearch - Elasticsearch-术语中的buckets_path agg

转载 作者:行者123 更新时间:2023-12-03 01:16:41 26 4
gpt4 key购买 nike

我正在尝试对术语(count_bucket)进行AVG计数,但是出现错误:

"buckets_path must reference either a number value or a single value numeric metric aggregation, got: [Bucket] at aggregation [count_bucket]"

这是我的查询:count_bucket是计数项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"
}
}
}
}

最佳答案

错误消息中描述了该问题:术语聚合不返回单个值,这与其他聚合(例如sumvalue_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"
}
}
}
}

关于elasticsearch - Elasticsearch-术语中的buckets_path agg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62269585/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com