# Bucket\_script not returning any results

**URL:** https://discuss.elastic.co/t/bucket-script-not-returning-any-results/164847
**Category:** Elasticsearch
**Created:** [January 18, 2019, 7:03pm UTC](https://discuss.elastic.co/t/bucket-script-not-returning-any-results/164847 "2019-01-18T19:03:39Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nielsoncr](https://avatars.discourse-cdn.com/v4/letter/n/c57346/32.png) [@nielsoncr](https://discuss.elastic.co/u/nielsoncr)
#### Post date: [January 18, 2019, 7:03pm UTC](https://discuss.elastic.co/t/bucket-script-not-returning-any-results/164847/1 "2019-01-18T19:03:39Z")

</div>

I have a query that returns docs aggregated by day, then by an internal metric call LocalRetryCount. I'd like the results to include with the LocalRetryCount buckets what percentage that bucket is of the overall. I found some examples that use a a bucket\_script to produce the percentage value, but no results are returned.

My query

{  
"size":0,  
"query":{  
"bool":{  
"must":[  
{  
"range":{  
"Timestamp":{  
"from":"now-1d",  
"to":"now"  
}  
}  
},  
{  
"query\_string":{  
"query":"LoggingProcess.ModuleId: 4",  
"analyze\_wildcard":true  
}  
}  
]  
}  
},  
"aggs":{  
"service\_calls\_per\_day":{  
"date\_histogram":{  
"field":"Timestamp",  
"interval":"day"  
},  
"aggs":{  
"total\_retry\_count":{  
"value\_count":{  
"field":"Metrics.Longs.LocalRetryCount"  
}  
},  
"local\_retry\_count":{  
"terms":{  
"field":"Metrics.Longs.LocalRetryCount"  
}  
},  
"percentage\_script":{  
"bucket\_script":{  
"buckets\_path":{  
"total\_count":"total\_retry\_count.value",  
"retry\_count":"local\_retry\_count.doc\_count"  
},  
"script":"100 \* params.total\_count / params.retry\_count"  
}  
}  
}  
}  
}  
}

The current results

{  
"took": 460,  
"timed\_out": false,  
"\_shards": {  
"total": 42,  
"successful": 42,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 5934883,  
"max\_score": 0,  
"hits":   
},  
"aggregations": {  
"service\_calls\_per\_day": {  
"buckets": [  
{  
"key\_as\_string": "2019-01-17T00:00:00.000Z",  
"key": 1547683200000,  
"doc\_count": 2411223,  
"total\_retry\_count": {  
"value": 1441179  
},  
"local\_retry\_count": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": [  
{  
"key": 0,  
"doc\_count": 1439567  
},  
{  
"key": 1,  
"doc\_count": 1610  
},  
{  
"key": 2,  
"doc\_count": 2  
}  
]  
}  
},  
{  
"key\_as\_string": "2019-01-18T00:00:00.000Z",  
"key": 1547769600000,  
"doc\_count": 3523660,  
"total\_retry\_count": {  
"value": 2235449  
},  
"local\_retry\_count": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": [  
{  
"key": 0,  
"doc\_count": 2229797  
},  
{  
"key": 1,  
"doc\_count": 4506  
},  
{  
"key": 2,  
"doc\_count": 573  
},  
{  
"key": 3,  
"doc\_count": 367  
},  
{  
"key": 4,  
"doc\_count": 170  
},  
{  
"key": 5,  
"doc\_count": 36  
}  
]  
}  
}  
]  
}  
}  
}

What I'd like is for the local\_retry\_count buckets to contain the percentage value, but I'm not getting any results from the percentage\_script aggregation. Any help is appreciated.

---

<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: [February 15, 2019, 7:03pm UTC](https://discuss.elastic.co/t/bucket-script-not-returning-any-results/164847/2 "2019-02-15T19:03:52Z")

</div>

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