# Script on aggregation value

**URL:** https://discuss.elastic.co/t/script-on-aggregation-value/52184
**Category:** Elasticsearch
**Created:** [June 8, 2016, 9:37am UTC](https://discuss.elastic.co/t/script-on-aggregation-value/52184 "2016-06-08T09:37:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![lore6673](https://avatars.discourse-cdn.com/v4/letter/l/e56c9b/32.png) [@lore6673](https://discuss.elastic.co/u/lore6673)
#### Post date: [June 8, 2016, 9:37am UTC](https://discuss.elastic.co/t/script-on-aggregation-value/52184/1 "2016-06-08T09:37:07Z")

</div>

Hello

I need to calculate a ratio between 2 aggregation.

This is my request

{  
"query": {  
"filtered": {  
"query": {  
"query\_string": {  
"query": "MERCH\_YEAR:2016",  
"analyze\_wildcard": true  
}  
},  
"filter": {  
"bool": {  
"must": [  
{  
"query": {  
"query\_string": {  
"analyze\_wildcard": true,  
"query": "MERCH\_YEAR:2016"  
}  
}  
}  
],  
"must\_not": []  
}  
}  
}  
},  
"size": 0,  
"aggs": {  
"total\_qty": {  
"sum": {  
"field": "SALES\_QTY"  
}  
},  
"total\_sales": {  
"sum": {  
"field": "SALES\_EURO"  
}  
},  
"AUR": {  
"bucket\_script": {  
"buckets\_path": {  
"my\_var1": "total\_sales",  
"my\_var2": "total\_qty"  
},  
"script": "my\_var1 / my\_var2"  
}  
}  
}  
}

But I get this error : nvalid pipeline aggregation named [AUR] of type [bucket\_script]. Only sibling pipeline aggregations are allowed at the top level.

How can I get the right result?

Thanks  
Lorenzo

---

<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: [July 5, 2017, 10:45pm UTC](https://discuss.elastic.co/t/script-on-aggregation-value/52184/2 "2017-07-05T22:45:22Z")

</div>


