# How can buckets be sorted by doc\_count ratio?

**URL:** <https://discuss.elastic.co/t/how-can-buckets-be-sorted-by-doc-count-ratio/250068>\
**Category:** Elasticsearch\
**Created:** [September 27, 2020, 2:13am UTC](https://discuss.elastic.co/t/how-can-buckets-be-sorted-by-doc-count-ratio/250068 "2020-09-27T02:13:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yanglingqiang](https://avatars.discourse-cdn.com/v4/letter/y/8e7dd6/32.png) [@yanglingqiang](https://discuss.elastic.co/u/yanglingqiang)\
**Post date:** [September 27, 2020, 2:13am UTC](https://discuss.elastic.co/t/how-can-buckets-be-sorted-by-doc-count-ratio/250068/1 "2020-09-27T02:13:21Z")

</div>

I have data  
{  
"id": 1,  
"buyer\_id": 101,  
"total\_count": 2  
}  
{  
"id": 2,  
"buyer\_id": 101,  
"total\_count": 2  
}

{  
"id": 3,  
"buyer\_id": 102,  
"total\_count": 1  
}  
After aggregation by buyer\_id, I want to sort by "doc\_count / total\_count", is this possible? How does it work?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 15, 2020, 4:45am UTC](https://discuss.elastic.co/t/how-can-buckets-be-sorted-by-doc-count-ratio/250068/2 "2020-10-15T04:45:40Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can copy and paste in Kibana dev console, click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<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 12, 2020, 4:46am UTC](https://discuss.elastic.co/t/how-can-buckets-be-sorted-by-doc-count-ratio/250068/3 "2020-11-12T04:46:00Z")

</div>

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