# Need help with aggregation query

**URL:** <https://discuss.elastic.co/t/need-help-with-aggregation-query/251640>\
**Category:** Elasticsearch\
**Created:** [October 10, 2020, 10:22am UTC](https://discuss.elastic.co/t/need-help-with-aggregation-query/251640 "2020-10-10T10:22:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![prabhakar\_talari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prabhakar_talari/32/46469_2.png) [@prabhakar\_talari](https://discuss.elastic.co/u/prabhakar_talari)\
**Post date:** [October 10, 2020, 10:22am UTC](https://discuss.elastic.co/t/need-help-with-aggregation-query/251640/1 "2020-10-10T10:22:30Z")

</div>

Hi All,

I am trying to write a query to get host and max cpu usage from metric beat data but i was not able to write exact query to get max cpu along with host name. for example below is the data

```
        "hostname:"host1","cpu_pct":"20"
        "hostname:"host1","cpu_pct":"10"

    "hostname:"host2","cpu_pct":"13"
    "hostname:"host2","cpu_pct":"17"

```

By using term aggregations i am able to get the unique host names but am looking unique host names along with max cpu usage like below

```
"hostname":"host1" 
"cpu_pct":"20"

"hostname":"host2",
"cpu_pct":"17"

```

Could some one help me how we can use term and max aggregations together

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:** [November 7, 2020, 10:22am UTC](https://discuss.elastic.co/t/need-help-with-aggregation-query/251640/2 "2020-11-07T10:22:40Z")

</div>

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