gpt4 book ai didi

elasticsearch - 如何在单个存储桶中使用复合聚合

转载 作者:行者123 更新时间:2023-12-02 23:09:01 24 4
gpt4 key购买 nike

下面的复合聚合查询

{
"query": {
"range": {
"orderedAt": {
"gte": 1591315200000,
"lte": 1591438881000
}
}
},
"size": 0,
"aggs": {
"my_buckets": {
"composite": {
"sources": [
{
"aggregation_target": {
"terms": {
"field": "supplierId"
}
}
}
]
},
"aggs": {
"aggregated_hits": {
"top_hits": {}
},
"filter": {
"bucket_selector": {
"buckets_path": {
"doc_count": "_count"
},
"script": "params.doc_count > 2"
}
}
}
}
}
}

返回类似下面的内容。
{
"took" : 67,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 34,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"my_buckets" : {
"after_key" : {
"aggregation_target" : "0HQI2G2HG00100G8"
},
"buckets" : [
{
"key" : {
"aggregation_target" : "0HQI2G0K000100G8"
},
"doc_count" : 4,
"aggregated_hits" : {...}
},
{
"key" : {
"aggregation_target" : "0HQI2G18G00100G8"
},
"doc_count" : 11,
"aggregated_hits" : {...}
},
{
"key" : {
"aggregation_target" : "0HQI2G2HG00100G8"
},
"doc_count" : 16,
"aggregated_hits" : {...}
}
]
}
}
}

根据查询中设置的条件,将汇总结果放入存储桶中。

有什么方法可以将它们放在一个存储桶中并分页考虑整个结果(例如本例中的31个文档)吗?

最佳答案

我认为你不能。除非您执行cardinalityscripted_metricterms聚合,否则文档的上下文不包含有关其他文档的信息。另外,一旦您基于supplierId整理文档,这首先就会破坏聚合的目的...

您上面编写的内容已经足够好,您必须在某些后期处理步骤中组合aggregated_hits

关于elasticsearch - 如何在单个存储桶中使用复合聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62255610/

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