# How to return multiple fields in a max aggregation

**URL:** <https://discuss.elastic.co/t/how-to-return-multiple-fields-in-a-max-aggregation/135780>\
**Category:** Elasticsearch\
**Created:** [June 13, 2018, 6:46pm UTC](https://discuss.elastic.co/t/how-to-return-multiple-fields-in-a-max-aggregation/135780 "2018-06-13T18:46:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Motez\_Musa](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@Motez\_Musa](https://discuss.elastic.co/u/Motez_Musa)\
**Post date:** [June 13, 2018, 6:46pm UTC](https://discuss.elastic.co/t/how-to-return-multiple-fields-in-a-max-aggregation/135780/1 "2018-06-13T18:46:09Z")

</div>

I have this aggregation:

> ```
> {
> "query": {
> "range": {
> "time_stamp": {
> "lt": "now",
> "gte": "now-1d"
> }
> }
> },
> "size": 0,
> "aggs": {
> "events_by_host": {
> "terms": {
> "field": "cell_host_the_app"
> },
> "aggs": {
> "events_by_date": {
> "date_histogram": {
> "field": "time_stamp",
> "interval": "30m"
> },
> "aggs": {
> "total_cpu": {
> "sum": {
> "field": "cpu_usgae_percentage"
> }
> },
> "max_cpu": {
> "max": {
> "field": "cpu_usgae_percentage"
> }
> }
> }
> },
> "max_aggregated_cpu": {
> "max_bucket": {
> "buckets_path": "events_by_date>total_cpu"
> }
> }
> }
> }
> }
> }
> 
> ```

I'm trying to figure out a way to return another field (called app\_name) from the max\_cpu sub aggregation that is performed. Is this possible?

---

<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 11, 2018, 6:46pm UTC](https://discuss.elastic.co/t/how-to-return-multiple-fields-in-a-max-aggregation/135780/2 "2018-07-11T18:46:24Z")

</div>

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