# Subtract two field count with aggregate in elastic search

**URL:** <https://discuss.elastic.co/t/subtract-two-field-count-with-aggregate-in-elastic-search/162044>\
**Category:** Elasticsearch\
**Created:** [December 25, 2018, 3:00am UTC](https://discuss.elastic.co/t/subtract-two-field-count-with-aggregate-in-elastic-search/162044 "2018-12-25T03:00:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akash\_Sahu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akash_sahu/32/39161_2.png) [@Akash\_Sahu](https://discuss.elastic.co/u/Akash_Sahu)\
**Post date:** [December 25, 2018, 3:00am UTC](https://discuss.elastic.co/t/subtract-two-field-count-with-aggregate-in-elastic-search/162044/1 "2018-12-25T03:00:15Z")

</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 22, 2019, 3:03am UTC](https://discuss.elastic.co/t/subtract-two-field-count-with-aggregate-in-elastic-search/162044/2 "2019-01-22T03:03:21Z")

</div>

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