# Sum of bucket script

**URL:** https://discuss.elastic.co/t/sum-of-bucket-script/254110
**Category:** Elasticsearch
**Created:** [November 3, 2020, 7:00am UTC](https://discuss.elastic.co/t/sum-of-bucket-script/254110 "2020-11-03T07:00:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![gokul275](https://avatars.discourse-cdn.com/v4/letter/g/e9bcb4/32.png) [@gokul275](https://discuss.elastic.co/u/gokul275)
#### Post date: [November 3, 2020, 7:00am UTC](https://discuss.elastic.co/t/sum-of-bucket-script/254110/1 "2020-11-03T07:00:48Z")

</div>

I am trying to achieve sum of bucket script values, Is it possible?

{  
"aggs": {  
"NAME": {  
"terms": {  
"field": "date",  
"size": 10  
},  
"aggs": {  
"bal": {  
"sum": {  
"field": "balance"  
}  
},  
"rdb" : {  
"sum": {  
"field": "rdb"  
}  
},  
"total" : {  
"bucket\_script": {  
"buckets\_path": {  
"bal" : "bal",  
"rpb" : "rdb"  
},  
"script": "params.bal \* params.rpb"  
}  
},  
"sum\_of\_total" : {  
"sum\_bucket": {  
"buckets\_path": "total"  
}  
}  
}  
}  
}  
}

getting the below error  
How to achieve sum of total?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [December 1, 2020, 7:00am UTC](https://discuss.elastic.co/t/sum-of-bucket-script/254110/2 "2020-12-01T07:00:51Z")

</div>

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