# Sorting facets results

**URL:** <https://discuss.elastic.co/t/sorting-facets-results/12291>\
**Category:** Elasticsearch\
**Created:** [June 6, 2013, 6:19am UTC](https://discuss.elastic.co/t/sorting-facets-results/12291 "2013-06-06T06:19:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuwar\_sahani\_2](https://avatars.discourse-cdn.com/v4/letter/k/fbc32d/32.png) [@kuwar\_sahani\_2](https://discuss.elastic.co/u/kuwar_sahani_2)\
**Post date:** [June 6, 2013, 6:19am UTC](https://discuss.elastic.co/t/sorting-facets-results/12291/1 "2013-06-06T06:19:55Z")

</div>

Hi  
Is it possible to order the faceted results based on the avg calculated by  
the facet. In my case a date\_histogram facet.

sample result  
"facets" : {  
"date\_facet"{  
"\_type" : "date\_histogram",  
"entries" : [  
{  
"time" : ,  
"count" : ,  
"min" : ,  
"max" :23,  
"total" : ,  
"total\_count" : ,  
"mean" :  
},  
{  
"time" : ,  
"count" : ,  
"min" : ,  
"max" :32,  
"total" : ,  
"total\_count" : ,  
"mean" :  
},  
{  
"time" : ,  
"count" : ,  
"min" : ,  
"max" :12,  
"total" : ,  
"total\_count" : ,  
"mean" :  
}  
]  
}  
}  
can i provide a scoring model where the faceted results get ordered based  
on the "max" value calculated ?  
how i want the results to be :  
"facets" : {  
"date\_facet"{  
"\_type" : "date\_histogram",  
"entries" : [  
{  
"time" : ,  
"count" : ,  
"min" : ,  
"max" :32,  
"total" : ,  
"total\_count" : ,  
"mean" :  
},  
{  
"time" : ,  
"count" : ,  
"min" : ,  
"max" :23,  
"total" : ,  
"total\_count" : ,  
"mean" :  
},  
{  
"time" : ,  
"count" : ,  
"min" : ,  
"max" :12,  
"total" : ,  
"total\_count" : ,  
"mean" :  
}  
]  
}  
}  
thanks in advance.  
Regards  
Kuwar

--  
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:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 6, 2013, 8:14am UTC](https://discuss.elastic.co/t/sorting-facets-results/12291/2 "2013-06-06T08:14:25Z")

</div>

Hey,

some facets support ordering (like the terms stats facet). The date  
histogram facet is strictly counted up by the timestamp (as it is used as  
aggregation base).  
Sorting this on client side should not be too hard.

--Alex

On Thu, Jun 6, 2013 at 8:19 AM, kuwar sahani [kuwarsahani@gmail.com](mailto:kuwarsahani@gmail.com) wrote:

> Hi  
> Is it possible to order the faceted results based on the avg calculated by  
> the facet. In my case a date\_histogram facet.
> 
> sample result  
> "facets" : {  
> "date\_facet"{  
> "\_type" : "date\_histogram",  
> "entries" : [  
> {  
> "time" : ,  
> "count" : ,  
> "min" : ,  
> "max" :23,  
> "total" : ,  
> "total\_count" : ,  
> "mean" :  
> },  
> {  
> "time" : ,  
> "count" : ,  
> "min" : ,  
> "max" :32,  
> "total" : ,  
> "total\_count" : ,  
> "mean" :  
> },  
> {  
> "time" : ,  
> "count" : ,  
> "min" : ,  
> "max" :12,  
> "total" : ,  
> "total\_count" : ,  
> "mean" :  
> }  
> ]  
> }  
> }  
> can i provide a scoring model where the faceted results get ordered based  
> on the "max" value calculated ?  
> how i want the results to be :  
> "facets" : {  
> "date\_facet"{  
> "\_type" : "date\_histogram",  
> "entries" : [  
> {  
> "time" : ,  
> "count" : ,  
> "min" : ,  
> "max" :32,  
> "total" : ,  
> "total\_count" : ,  
> "mean" :  
> },  
> {  
> "time" : ,  
> "count" : ,  
> "min" : ,  
> "max" :23,  
> "total" : ,  
> "total\_count" : ,  
> "mean" :  
> },  
> {  
> "time" : ,  
> "count" : ,  
> "min" : ,  
> "max" :12,  
> "total" : ,  
> "total\_count" : ,  
> "mean" :  
> }  
> ]  
> }  
> }  
> thanks in advance.  
> Regards  
> Kuwar
> 
> --  
> 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:32am UTC](https://discuss.elastic.co/t/sorting-facets-results/12291/3 "2017-07-06T02:32:40Z")

</div>


