# Sort buckets by count in terms aggregation using java api client

**URL:** https://discuss.elastic.co/t/sort-buckets-by-count-in-terms-aggregation-using-java-api-client/359215
**Category:** Elasticsearch
**Created:** [May 9, 2024, 8:15pm UTC](https://discuss.elastic.co/t/sort-buckets-by-count-in-terms-aggregation-using-java-api-client/359215 "2024-05-09T20:15:14Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Rohini1](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@Rohini1](https://discuss.elastic.co/u/Rohini1)
#### Post date: [May 9, 2024, 8:15pm UTC](https://discuss.elastic.co/t/sort-buckets-by-count-in-terms-aggregation-using-java-api-client/359215/1 "2024-05-09T20:15:14Z")

</div>

I want to sort buckets by doc count in terms aggregation and also sort buckets by sub aggregation
