# Sort based on statistical facet values

**URL:** https://discuss.elastic.co/t/sort-based-on-statistical-facet-values/14013
**Category:** Elasticsearch
**Created:** [October 18, 2013, 11:28am UTC](https://discuss.elastic.co/t/sort-based-on-statistical-facet-values/14013 "2013-10-18T11:28:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Bjorn\_Brathen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bjorn_brathen/32/2029_2.png) [@Bjorn\_Brathen](https://discuss.elastic.co/u/Bjorn_Brathen)
#### Post date: [October 18, 2013, 11:28am UTC](https://discuss.elastic.co/t/sort-based-on-statistical-facet-values/14013/1 "2013-10-18T11:28:30Z")

</div>

Hi,

I try to implement a "most popular"-item sort, where I want to use  
statistical information about my ES-documents. I have looked into the  
statistical facet, but I'm not able to use its values in my sort. I'm  
trying to do this as a single query. I have got it to work by first get the  
statistical facet, and then do the query with the custom sort function. Is  
it possible to do this in one request? I'm using the Java API.

best regards,

Bjørn Bråthen

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [October 18, 2013, 12:31pm UTC](https://discuss.elastic.co/t/sort-based-on-statistical-facet-values/14013/2 "2013-10-18T12:31:56Z")

</div>

Hi Bjørn

No it isn't possible to do this in one query. Facets are calculated AFTER  
the search request is performed, so the two-phase query you're already  
using is the way to go

clint

On 18 October 2013 13:28, Bjørn Bråthen [bjorbrat88@gmail.com](mailto:bjorbrat88@gmail.com) wrote:

> Hi,
> 
> I try to implement a "most popular"-item sort, where I want to use  
> statistical information about my ES-documents. I have looked into the  
> statistical facet, but I'm not able to use its values in my sort. I'm  
> trying to do this as a single query. I have got it to work by first get the  
> statistical facet, and then do the query with the custom sort function. Is  
> it possible to do this in one request? I'm using the Java API.
> 
> best regards,
> 
> Bjørn Bråthen
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:11am UTC](https://discuss.elastic.co/t/sort-based-on-statistical-facet-values/14013/3 "2017-07-06T02:11:45Z")

</div>


