# How to perform the aggregation with doc\_count value

**URL:** <https://discuss.elastic.co/t/how-to-perform-the-aggregation-with-doc-count-value/173946>\
**Category:** Elasticsearch\
**Created:** [March 26, 2019, 2:19pm UTC](https://discuss.elastic.co/t/how-to-perform-the-aggregation-with-doc-count-value/173946 "2019-03-26T14:19:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RajeshAJ](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@RajeshAJ](https://discuss.elastic.co/u/RajeshAJ)\
**Post date:** [March 26, 2019, 2:19pm UTC](https://discuss.elastic.co/t/how-to-perform-the-aggregation-with-doc-count-value/173946/1 "2019-03-26T14:19:14Z")

</div>

is there any way to perform the aggregation for the string filed,

I tried with bucket\_script, but it required for the int or number value.  
note: I need to perform the arithmetic operation based on the doc\_count

**Request:**

GET logstash-\*/\_search  
{  
"size": 0,  
"aggs": {  
"2": {  
"date\_histogram": {  
"field": "@timestamp",  
"interval": "1d",  
"time\_zone": "Europe/London",  
"min\_doc\_count": 0  
},  
"aggs": {  
"3" : {  
"filters" : {  
"filters" : {  
"confirmed": {  
"query\_string": {  
"query": "("status=Booking Confirmed")",  
"analyze\_wildcard": true  
}  
}  
}  
}  
}  
,"4" : {  
"filters" : {  
"filters" : {  
"cancelled": {  
"query\_string": {  
"query": "("status=Booking Cancelled")",  
"analyze\_wildcard": true  
}  
}  
}  
}  
}  
,  
"succesrate": {  
"bucket\_script": {  
"buckets\_path": {  
"one": "3.\_count",  
"two": "4.\_count"  
},  
"script": "params.one / params.two"  
}  
}  
}  
}

```
  }

```

}

**response:**  
{  
"error": {  
"root\_cause": ,  
"type": "search\_phase\_execution\_exception",  
"reason": "",  
"phase": "fetch",  
"grouped": true,  
"failed\_shards": ,  
"caused\_by": {  
"type": "aggregation\_execution\_exception",  
"reason": "buckets\_path must reference either a number value or a single value numeric metric aggregation, got: java.lang.Object"  
}  
},  
"status": 503  
}

---

<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:** [April 23, 2019, 2:19pm UTC](https://discuss.elastic.co/t/how-to-perform-the-aggregation-with-doc-count-value/173946/2 "2019-04-23T14:19:18Z")

</div>

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