比如:得到所有订单数量大于 10 的用户总数,类似于 SQL 语句:
select count(1) from (
select count(1) as cnt from orders group by userid having cnt >= 10
);
1
weofuh 2021-02-05 10:53:49 +08:00
{
"aggs": { "user_order_cnt": { "terms": { "field": "userid" }, "aggs": { "count_bucket_selector": { "bucket_selector": { "buckets_path": { "count" :"_count" }, "script": "params.count>10" } } } } } } |
3
rykinia 2021-02-05 13:32:49 +08:00
```
{ "aggs": { "cnt": { "terms": { "field": "userid", "size": 1000, "min_doc_count": 10 } } }, "size": 0 } ``` 结果: ``` "buckets" : [ { "key" : "320581180", "doc_count" : 20 }, { "key" : "2207021711", "doc_count" : 10 }, ``` 这个 doc_count 不就是数量吗 |
4
JJstyle OP @rykinia 不是的,我要的是所有 doc_count>10 的 buckets 的数量,而不是 buckets 的集合
|
5
tairan2006 2021-02-07 12:57:28 +08:00
老哥,你不知道`_sql/translate`这个工具么
|