# Median of the result of top\_hits

**URL:** https://discuss.elastic.co/t/median-of-the-result-of-top-hits/40905
**Category:** Elasticsearch
**Created:** [February 3, 2016, 7:31pm UTC](https://discuss.elastic.co/t/median-of-the-result-of-top-hits/40905 "2016-02-03T19:31:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bsideup](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bsideup/32/7565_2.png) [@bsideup](https://discuss.elastic.co/u/bsideup)
#### Post date: [February 3, 2016, 7:31pm UTC](https://discuss.elastic.co/t/median-of-the-result-of-top-hits/40905/1 "2016-02-03T19:31:30Z")

</div>

Hi!

I have top\_hits aggregation and I want to calculate median from it, but ES says:  
Aggregator [hits] of type [top\_hits] cannot accept sub-aggregations

Maybe there are some other ways of doing such things?  
My data looks like this:  
{  
"key": "string",  
"creation\_date": "date",  
"metric":"number"  
}

And I want to aggregate them by key, take top 3 hits by creation\_date and calculate median of "metric" field.

Thanks!

---

<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 5, 2017, 11:19pm UTC](https://discuss.elastic.co/t/median-of-the-result-of-top-hits/40905/2 "2017-07-05T23:19:12Z")

</div>


