# Facets and Multiple Sorts

**URL:** <https://discuss.elastic.co/t/facets-and-multiple-sorts/16570>\
**Category:** Elasticsearch\
**Created:** [March 24, 2014, 9:56pm UTC](https://discuss.elastic.co/t/facets-and-multiple-sorts/16570 "2014-03-24T21:56:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erich\_Lin](https://avatars.discourse-cdn.com/v4/letter/e/85e7bf/32.png) [@Erich\_Lin](https://discuss.elastic.co/u/Erich_Lin)\
**Post date:** [March 24, 2014, 9:56pm UTC](https://discuss.elastic.co/t/facets-and-multiple-sorts/16570/1 "2014-03-24T21:56:21Z")

</div>

Do facets support either:

1. Deterministic/stable sorting if there are equal values
2. If not, a way to allow this using multiple sorts. Sort first by A, then  
if A's are equal, sort by B.

This is my query:

POST /some\_index/\_search  
{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
}  
}  
},  
"facets": {  
"facet\_name": {  
"terms\_stats": {  
"key\_field": "bucket\_id",  
"value\_field": "price",  
"order": "mean",  
"size": 100  
}  
}  
}  
}'

If bucket\_id 90 , 91 .... 100, 101.. 105 all have the same mean price, then

1. would I potentially get a different result set each time because of a  
non-deterministic sort?
2. If so, how do I change this specific query to order first by mean price  
and then SECOND by bucket\_id.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/58efd436-1595-4ba1-bfb5-3f9ae757bb77%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/58efd436-1595-4ba1-bfb5-3f9ae757bb77%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:40am UTC](https://discuss.elastic.co/t/facets-and-multiple-sorts/16570/2 "2017-07-06T01:40:58Z")

</div>


