您可以利用“
统计数据桶聚合”来获取存储桶数。
以下是查询的方式。
汇总查询:
POST visitor_carts/_search{ "size": 0, "aggs": { "visitors": { "terms": { "field" : "visitor_id" }, "aggs": { "one_purchase": { "bucket_selector": { "buckets_path": { "nb_purchases": "_count" }, "script": "params.nb_purchases == 3" } } } }, "mybucketcount":{ "stats_bucket": { "buckets_path":"visitors._count" } } }}汇总结果:
{ "took": 1, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 8, "max_score": 0, "hits": [] }, "aggregations": { "visitors": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "2", "doc_count": 3 }, { "key": "3", "doc_count": 3 } ] }, "mybucketcount": { "count": 2, <---- This is the count you are looking for "min": 3, "max": 3, "avg": 3, "sum": 6 } }}让我知道是否有帮助!



