About aggregates the results of buckets twice

hello,
Elastic 6.3.0

Now,We hive a table of Consumption details.(A person has multiple consumption records ).

First ,we want to Calculate a person's total consumption(need to agg).

Then we want to get all the people who consume more than $500.(It's the total, not the details.).

So we need to aggregate twice on the basis of calculating a person's total consumption amount.

Like the sql:
select count(1)
from (select *
from (select mobile_nbr, sum(trans_amt) total_trans_amt
from activity_detail
group by mobile_nbr) t
where t.total_trans_amt > 500) tt

Excuse me, do es support this query?

best wish to you
thanks

It sounds like you're looking for the bucket selector aggregation. The docs have an example that's very similar to what you're trying to do.

@abdon
hello,thanks for your answer.
I had tried the bucket selector aggregation.But the result is the details are not the total.
I want to get the number of people that is not people's details.
Can we get the result~

I think you would have to do that client-side: count the number of buckets that the Bucket Selector aggregation returns.

@abdon
ok,I see.
thank you very much

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.