# Strange secondary sorting for TermsFacet (with identical counts)

**URL:** <https://discuss.elastic.co/t/strange-secondary-sorting-for-termsfacet-with-identical-counts/4456>\
**Category:** Elasticsearch\
**Created:** [May 23, 2011, 11:06am UTC](https://discuss.elastic.co/t/strange-secondary-sorting-for-termsfacet-with-identical-counts/4456 "2011-05-23T11:06:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_Fiedler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jan_fiedler/32/2518_2.png) [@Jan\_Fiedler](https://discuss.elastic.co/u/Jan_Fiedler)\
**Post date:** [May 23, 2011, 11:06am UTC](https://discuss.elastic.co/t/strange-secondary-sorting-for-termsfacet-with-identical-counts/4456/1 "2011-05-23T11:06:45Z")

</div>

I noticed a strange sorting of TermsFacet entries returned by ES. If  
you have 2 documents with a string field providing values 'foo' and  
'bar' and you run a TermsFacet on this field (ordered by count), you  
get two entries with a count of 1 (as expected). I would have expected  
value 'bar' to show up before 'foo' (i.e. ascending alphabetic  
sorting) for entries with the same count. It seems to be sorted  
descending on the term value though.

Find a curl based reproduction of the problem here: [https://gist.github.com/986550](https://gist.github.com/986550)

If the behavior is as designed, is there an API to provide my own  
comparator for sorting entries returned by ES ? This would also be  
useful for providing correct locale specific sorting of facet term  
values.

---

<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:05am UTC](https://discuss.elastic.co/t/strange-secondary-sorting-for-termsfacet-with-identical-counts/4456/2 "2017-07-06T04:05:34Z")

</div>


