# Range by Sum Result

**URL:** https://discuss.elastic.co/t/range-by-sum-result/48018
**Category:** Elasticsearch
**Created:** [April 21, 2016, 9:58am UTC](https://discuss.elastic.co/t/range-by-sum-result/48018 "2016-04-21T09:58:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JayMiao](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@JayMiao](https://discuss.elastic.co/u/JayMiao)
#### Post date: [April 21, 2016, 9:58am UTC](https://discuss.elastic.co/t/range-by-sum-result/48018/1 "2016-04-21T09:58:39Z")

</div>

Data:  
{"a":"abc\_1","b":"abc","time\_used":0.64}  
{"a":"abc\_1\_1","b":"abc","time\_used":0.64}  
{"a":"abc\_1\_2","b":"abc","time\_used":0.64}  
{"a":"fgh\_1","b":"fgh","time\_used":0.457}  
{"a":"fgh\_1\_1","b":"fgh","time\_used":0.457}  
{"a":"fgh\_1\_1\_2","b":"fgh","time\_used":0.457}  
{"a":"edx\_1","b":"edx","time\_used":0.48}  
{"a":"edx\_2","b":"edx","time\_used":0.48}  
{"a":"edx\_2\_1","b":"edx","time\_used":0.48}

I want to calculate the "sum(time\_used) group by" result and then see the range of sum(time\_used)

query like this  
`{ "aggs": { "2": { "terms": { "field": "b", "size": 5, "order": { "2-orderAgg": "desc" } }, "aggs": { "2-orderAgg": { "sum": { "field": "time_used" }, "aggs": { "1-aggs": { "range": { "field": "2-orderAgg.value", "ranges": [{ "from": 0, "to": 1.5 }, { "from": 1.5, "to": 2 }] } } } } } } } }`

the error message:  
Aggregator [2-orderAgg] of type [sum] cannot accept sub-aggregations

the range field cannot use the result of sum from upper aggregation?

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [April 21, 2016, 11:01am UTC](https://discuss.elastic.co/t/range-by-sum-result/48018/2 "2016-04-21T11:01:55Z")

</div>

Unfortunately this is not currently possible in the Aggregations feature. We do have an issue for it though which you can track here: [https://github.com/elastic/elasticsearch/issues/17590](https://github.com/elastic/elasticsearch/issues/17590)

---

<div class="post-metadata">

### Author: ![JayMiao](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@JayMiao](https://discuss.elastic.co/u/JayMiao)
#### Post date: [April 21, 2016, 11:20am UTC](https://discuss.elastic.co/t/range-by-sum-result/48018/3 "2016-04-21T11:20:51Z")

</div>

It would be cool to have a concept like **temporary-table** in mysql.  
The user can use the column in tmp-table as the input of sub-aggregation.

---

<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:57pm UTC](https://discuss.elastic.co/t/range-by-sum-result/48018/4 "2017-07-05T22:57:20Z")

</div>


