Range by Sum Result

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?

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

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.