# How can i Disply the result of division between two field?

**URL:** https://discuss.elastic.co/t/how-can-i-disply-the-result-of-division-between-two-field/98502
**Category:** Kibana
**Created:** [August 28, 2017, 3:32am UTC](https://discuss.elastic.co/t/how-can-i-disply-the-result-of-division-between-two-field/98502 "2017-08-28T03:32:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![minchina](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@minchina](https://discuss.elastic.co/u/minchina)
#### Post date: [August 28, 2017, 3:32am UTC](https://discuss.elastic.co/t/how-can-i-disply-the-result-of-division-between-two-field/98502/1 "2017-08-28T03:32:39Z")

</div>

Hi Guys, currently, i have a requirement about kibana visualize tab, i want to display the division result of two sum(field). how can i display that result.

my script is  
{  
"query": {  
"bool": {  
"must": [  
{  
"query\_string": {  
"analyze\_wildcard": true,  
"query": "站点"  
}  
},  
{  
"match\_phrase": {  
"tradeType": {  
"query": "Recharge"  
}  
}  
},  
{  
"range": {  
"dbTime": {  
"gte": 1503803048541,  
"lte": 1503889448541,  
"format": "epoch\_millis"  
}  
}  
}  
],  
"must\_not": []  
}  
},  
"size": 0,  
"\_source": {  
"excludes": []  
},  
"aggs": {  
"5": {  
"date\_range": {  
"field": "dbTime",  
"ranges": [  
{  
"from": "now-1d/d+2h",  
"to": "now/d+2h"  
}  
]  
},  
"aggs": {  
"4": {  
"terms": {  
"field": "stationCode.keyword",  
"size": 100,  
"order": {  
"1": "desc"  
}  
},  
"aggs": {  
"1": {  
"sum": {  
"field": "payAmount"  
}  
},  
"3": {  
"sum": {  
"field": "tradeAmount"  
}  
},  
"division" : {  
"bucket\_script": {  
"buckets\_path": {  
"my\_var1": "1",  
"my\_var2": "3"  
},  
"script": "params.my\_var1 / params.my\_var2"  
}  
}  
}  
}  
}  
}  
}  
}

i want to display the division in the table.

---

<div class="post-metadata">

### Author: ![rashmi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rashmi/32/16391_2.png) [@rashmi](https://discuss.elastic.co/u/rashmi)
#### Post date: [August 28, 2017, 6:31pm UTC](https://discuss.elastic.co/t/how-can-i-disply-the-result-of-division-between-two-field/98502/2 "2017-08-28T18:31:05Z")

</div>

Hi

Possibly this can be achieved by Pipeline aggregations in ES. . These are aggregations that work on the result of other aggregations. In your example, you could use a bucket\_script pipeline aggregation. For ex: I just considered sum\_1 and sum\_2

```auto
"aggs": {
  "sum_1": {
    "sum": {
      "field": "abc"
    }
  },
  "sum_2": {
    "sum": {
      "field": "def"
    }
  },
  "division": {
    "bucket_script": {
      "buckets_path": {
        "my_var1": "sum_1",
        "my_var2": "sum_2"
      },
      "script": "params.my_var1 / params.my_var2"
    }
  }
}

```

Also follow along the math count detailed post in kibana discuss :[Doing Math over count of events](https://discuss.elastic.co/t/doing-math-over-count-of-events/97278) . This might help as well.

thanks  
Rashmi

---

<div class="post-metadata">

### Author: ![minchina](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@minchina](https://discuss.elastic.co/u/minchina)
#### Post date: [August 29, 2017, 12:48am UTC](https://discuss.elastic.co/t/how-can-i-disply-the-result-of-division-between-two-field/98502/3 "2017-08-29T00:48:15Z")

</div>

@rashmi, thanks for your answer, yeah, you are right, i just don'w know how to display the result of division in kibana visualize data table, do you know how to let the result display in the data table?thanks

---

<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: [September 26, 2017, 12:48am UTC](https://discuss.elastic.co/t/how-can-i-disply-the-result-of-division-between-two-field/98502/4 "2017-09-26T00:48:42Z")

</div>

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