# Query to determine percentage

**URL:** <https://discuss.elastic.co/t/query-to-determine-percentage/235752>\
**Category:** Elasticsearch\
**Created:** [June 4, 2020, 12:37pm UTC](https://discuss.elastic.co/t/query-to-determine-percentage/235752 "2020-06-04T12:37:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![leandroribeiro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandroribeiro/32/69702_2.png) [@leandroribeiro](https://discuss.elastic.co/u/leandroribeiro)\
**Post date:** [June 4, 2020, 12:37pm UTC](https://discuss.elastic.co/t/query-to-determine-percentage/235752/1 "2020-06-04T12:37:36Z")

</div>

Hi all,

I have a query that returns an aggregation for a certain term:

```auto
    {
      "_source": ["id", "status","message"],
      "query": {    
        "bool": {
          "must": [
    	{"exists": { "field": "status" }}
          ],
          "filter": [
            { "range": { "@timestamp": { "gte": "now-1h" }}}
          ]
        }
      },
      "aggs" : {	
        "distinct_status" : { "terms" : { "field" : "status" }}
      }
    }

```

The result includes:

```auto
    "hits": {
            "total": {
                "value": 193,
                "relation": "eq"
            },
    (...)
    "aggregations": {
            "mission_endings": {
                "doc_count_error_upper_bound": 0,
                "sum_other_doc_count": 0,
                "buckets": [
                    {
                        "key": "Success",
                        "doc_count": 141
                    },
                    {
                        "key": "Error",
                        "doc_count": 26
                    },
                    {
                        "key": "Warning",
                        "doc_count": 26
                    }
                ]
            }
        }

```

Is there a way to write a query that returns, for example, the ratio of Success / Total?

Thank you

---

<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:** [July 2, 2020, 12:37pm UTC](https://discuss.elastic.co/t/query-to-determine-percentage/235752/2 "2020-07-02T12:37:42Z")

</div>

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