Hi ice2021,
it is perfectly doable with a Bucket script aggregation | Elasticsearch Guide [7.12] | Elastic
The tricky part is the bucket path: follow the link in the mentioned doc to "bucket path syntax".
Tip: the account should be your top aggregation. Then, for each account you can aggregate by index, and get the sum of prices. your final bucket-script-aggregation will just substract the 2 sums, using bucket paths which contain the index names (that you should know).
1 Like