# Subtraction two fields aggregate count in elasticsearch script

**URL:** https://discuss.elastic.co/t/subtraction-two-fields-aggregate-count-in-elasticsearch-script/162008
**Category:** Elasticsearch
**Created:** [December 24, 2018, 3:01pm UTC](https://discuss.elastic.co/t/subtraction-two-fields-aggregate-count-in-elasticsearch-script/162008 "2018-12-24T15:01:47Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Sanjeev7](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@Sanjeev7](https://discuss.elastic.co/u/Sanjeev7)
#### Post date: [December 24, 2018, 3:01pm UTC](https://discuss.elastic.co/t/subtraction-two-fields-aggregate-count-in-elasticsearch-script/162008/1 "2018-12-24T15:01:47Z")

</div>

I am getting below output after apply aggregate but i have perform subtraction on "key": "in-completed","doc\_count": 4 and "key": "completed", "doc\_count": 2  
expected  
output - [in-completed][doc\_count] - [completed][doc\_count]

Please tell me if its possible in elastic search script because subtraction count need display in kibana dashboard

output-  
{  
"took": 4,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 6,  
"max\_score": 0,  
"hits":   
},  
"aggregations": {  
"sessionLengthData": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": [  
{  
"key": "in-completed",  
"doc\_count": 4,  
"p-status": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets":   
}  
},  
{  
"key": "completed",  
"doc\_count": 2,  
"p-status": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets":   
}  
}  
]  
}  
}  
}

---

<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: [January 21, 2019, 3:13pm UTC](https://discuss.elastic.co/t/subtraction-two-fields-aggregate-count-in-elasticsearch-script/162008/2 "2019-01-21T15:13:53Z")

</div>

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