I need to compute a pipeline aggregation in ElasticSearch and I can't figure out how to express it.
Each document has an email address and an amount. I need to output range buckets of amount counts, grouped by unique email.
{ "0 - 99": 300, "100 - 400": 100 ...}
Would basically be the expected output (the keys would be transformed in my application code), indicating that 300 unique emails have cumulatively received at least 99 (amount) across all documents.
Intuitively, I would expect a query like below. However, range does not appear to be a buckets aggregation (or allow buckets_path).
What is the correct approach here?
{
aggs: {
users: {
terms: {
field: "email"
},
aggs: {
amount_received: {
sum: {
field: "amount"
}
}
}
},
amount_ranges: {
range: {
buckets_path: "users>amount_received",
ranges: [
{ to: 99.0 },
{ from: 100.0, to: 299.0 },
{ from: 300.0, to: 599.0 },
{ from: 600.0 }
]
}
}
}
}