data source:
area amout
bj 100
sh 200
sh 200
I need calculate the result:
area amout percentage
bj 300 300/500
sh 200 200/500
How to achieve this? thanks!
I try to do this,but it is wrong.
curl -X POST "http://localhost:9200/corp_info6/_doc/_search" -H 'Content-Type: application/json' -d'
{
"aggs": {
"ind_terms": {
"terms": {
"field": "area"
},
"aggs": {
"sum_weight": {
"sum": {
"field": "amout "
}
},
"t-percentage": {
"bucket_script": {
"buckets_path": {
"sum1": "sum_weight",
"total": "sum_sum_weight"
},
"script": "params.sum1 / params.total "
}
}
}
},
"sum_sum_weight": {
"sum_bucket": {
"buckets_path": "ind_terms>sum_weight"
}
}
}
}'