# How to find percentage using doc\_count in elastic query

**URL:** https://discuss.elastic.co/t/how-to-find-percentage-using-doc-count-in-elastic-query/221394
**Category:** Elasticsearch
**Created:** [February 28, 2020, 9:17am UTC](https://discuss.elastic.co/t/how-to-find-percentage-using-doc-count-in-elastic-query/221394 "2020-02-28T09:17:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![rahulkothanath](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahulkothanath/32/99122_2.png) [@rahulkothanath](https://discuss.elastic.co/u/rahulkothanath)
#### Post date: [February 28, 2020, 9:17am UTC](https://discuss.elastic.co/t/how-to-find-percentage-using-doc-count-in-elastic-query/221394/1 "2020-02-28T09:17:17Z")

</div>

I am having an elastic result like below.  
{  
"key" : "2020-02-18T09:10:14.453Z-2020-02-26T09:10:14.453Z",  
"from" : 1.582017014453E12,  
"from\_as\_string" : "2020-02-18T09:10:14.453Z",  
"to" : 1.582708214453E12,  
"to\_as\_string" : "2020-02-26T09:10:14.453Z",  
"doc\_count" : 11237096,  
"ISG-TMX-FAILED" : {  
"doc\_count" : 4731815  
}  
}

I want to get the value 4731815/11237096 to get the percentage of failures.

my query is below:

```
POST index/_search
{
  "query": {
    "bool": {
      "filter": {
        "bool": {
      "must": [
       
        {"match": {"D": "ISp"}}
        
      ]
    }
      }
    }
  }, 
    "aggs" : {
        "ISG-TMX-YES" : {
           "date_range": {
             "field": "td.XCN",
             "ranges": [
               {
                 "from": "now-2d",
                 "to": "now"
                 
               },
               {
                 "from": "now-10d",
                 "to": "now-2d"
               
               }
             ]
           },
           "aggs": {
             "ISG-TMX-FAILED": {
               "missing": {
                 "field": "tmx.compositeKey.requestTimeStamp"
               }
             }
           }
        }
}
  
  
}
```

---

<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: [March 27, 2020, 9:17am UTC](https://discuss.elastic.co/t/how-to-find-percentage-using-doc-count-in-elastic-query/221394/2 "2020-03-27T09:17:21Z")

</div>

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