# Sorting on facet results?

**URL:** https://discuss.elastic.co/t/sorting-on-facet-results/4723
**Category:** Elasticsearch
**Created:** [June 28, 2011, 10:20am UTC](https://discuss.elastic.co/t/sorting-on-facet-results/4723 "2011-06-28T10:20:10Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Hari\_Shankar](https://avatars.discourse-cdn.com/v4/letter/h/ad7895/32.png) [@Hari\_Shankar](https://discuss.elastic.co/u/Hari_Shankar)
#### Post date: [June 28, 2011, 10:20am UTC](https://discuss.elastic.co/t/sorting-on-facet-results/4723/1 "2011-06-28T10:20:10Z")

</div>

Hi,

Is there any combination of queries I can use to sort the results based on  
facet results?

For example, I have three fields, "Date", "Hits" and "Logins" in a doc. Now,  
given a date range, I need to get all the documents, such that the total of  
"Hits" in the given date range is greater than 1000 and I need to sort the  
result based on "Logins". Is this possible in es?

I get a feeling this can be done using terms\_stats facet but I am not able  
to figure out how.

Thanks for your time,  
Hari

---

<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 6, 2017, 4:02am UTC](https://discuss.elastic.co/t/sorting-on-facet-results/4723/2 "2017-07-06T04:02:24Z")

</div>


