# Scripted fields from the result of aggregations and the nested aggregations

**URL:** <https://discuss.elastic.co/t/scripted-fields-from-the-result-of-aggregations-and-the-nested-aggregations/22368>\
**Category:** Elasticsearch\
**Created:** [February 24, 2015, 11:24pm UTC](https://discuss.elastic.co/t/scripted-fields-from-the-result-of-aggregations-and-the-nested-aggregations/22368 "2015-02-24T23:24:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cong\_yue](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cong_yue/32/53106_2.png) [@cong\_yue](https://discuss.elastic.co/u/cong_yue)\
**Post date:** [February 24, 2015, 11:24pm UTC](https://discuss.elastic.co/t/scripted-fields-from-the-result-of-aggregations-and-the-nested-aggregations/22368/1 "2015-02-24T23:24:26Z")

</div>

## I have a aggregation as

## GET /ats/\_search { "size": 0, "aggs": { "accessTimes": { "date\_histogram": { "field": "accessTime", "interval": "hour" }, "aggs": { "hit\_docs": { "filter": { "terms": { "cacheResult": ["tcp\_mem\_hit","tcp\_hit","tcp\_refresh\_hit"] } ....

## And the response is

## { .... "aggregations": { "accessTimes": { "buckets": [ { "key\_as\_string": "2015-02-19T11:00:00.000Z", "key": 1424343600000, "doc\_count": 14, "hit\_docs": { "doc\_count": 13 } }, { "key\_as\_string": "2015-02-19T12:00:00.000Z", "key": 1424347200000, "doc\_count": 52, "hit\_docs": { "doc\_count": 41 } }, { "key\_as\_string": "2015-02-19T13:00:00.000Z", "key": 1424350800000, "doc\_count": 231, "hit\_docs": { "doc\_count": 136 } }, { "key\_as\_string": "2015-02-19T14:00:00.000Z", "key": 1424354400000, "doc\_count": 13161, "hit\_docs": { "doc\_count": 8957 } }, { "key\_as\_string": "2015-02-19T15:00:00.000Z", "key": 1424358000000, "doc\_count": 8971, "hit\_docs": { "doc\_count": 5631 } ...

I want to know whether there is some way to access the field of  
_aggregations.buckets.doc\_count_ and a\*ggregations.buckets.hit\_docs.doc\_count  
\*and calculate the hit ration from these two values. Finally, I want to  
view it from kiban4.

Thanks,  
Cong

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/78241d3c-a51f-4b72-8708-5b2dc7583cbb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/78241d3c-a51f-4b72-8708-5b2dc7583cbb%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:30am UTC](https://discuss.elastic.co/t/scripted-fields-from-the-result-of-aggregations-and-the-nested-aggregations/22368/2 "2017-07-06T00:30:21Z")

</div>


