# Term facet ordering

**URL:** <https://discuss.elastic.co/t/term-facet-ordering/13256>\
**Category:** Elasticsearch\
**Created:** [August 19, 2013, 11:22am UTC](https://discuss.elastic.co/t/term-facet-ordering/13256 "2013-08-19T11:22:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![roberto\_morandeira](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@roberto\_morandeira](https://discuss.elastic.co/u/roberto_morandeira)\
**Post date:** [August 19, 2013, 11:22am UTC](https://discuss.elastic.co/t/term-facet-ordering/13256/1 "2013-08-19T11:22:32Z")

</div>

Hi,

I have an issue related to the ordering of the term facets. It seems that  
the ordering does not work properly when there are upper / lower case.

This is the facet definition:

{  
"size": 0,  
"facets" : {  
"location" : {  
"terms" : {  
"field" : "location.untouched",  
"size" : 10,  
"order" : "term"  
}  
}  
}  
}

And this is the response:

{  
"took": 0,  
"timed\_out": false,  
"\_shards": {  
"total": 1,  
"successful": 1,  
"failed": 0  
},  
"hits": {  
"total": 814,  
"max\_score": 1,  
"hits": []  
},  
"facets": {  
"location": {  
"\_type": "terms",  
"missing": 49,  
"total": 781,  
"other": 739,  
"terms": [  
{  
"term": "AR - Little Rock",  
"count": 2  
},  
{  
"term": "AZ -Phoenix",  
"count": 3  
},  
{  
"term": "Aberdeen",  
"count": 1  
},  
{  
"term": "Abu Dhabi",  
"count": 1  
},  
{  
"term": "Alberta - Calgary",  
"count": 1  
},  
{  
"term": "Almere",  
"count": 11  
},  
{  
"term": "Amazonas - Manaus",  
"count": 1  
},  
{  
"term": "Amsterdam",  
"count": 18  
},  
{  
"term": "Athens",  
"count": 1  
},  
{  
"term": "Bangkok",  
"count": 3  
}  
]  
}  
}  
}

"AR - Little Rock" should not be the first location.

Best Regards,  
Roberto.

--  
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:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [August 19, 2013, 12:48pm UTC](https://discuss.elastic.co/t/term-facet-ordering/13256/2 "2013-08-19T12:48:18Z")

</div>

from an encoding point of view this seems to be OK to me? A \< B \< a \< b so  
"AR" \< "Ab"  
I am not saying that this is ok from an application point of view but that  
is a different story. I'd ask you to open a dev issues for this to maybe  
plug in  
some colaltion based sorting?

simon

On Monday, August 19, 2013 1:22:32 PM UTC+2, [roberto.m...@gmail.com](mailto:roberto.m...@gmail.com) wrote:

> Hi,
> 
> I have an issue related to the ordering of the term facets. It seems that  
> the ordering does not work properly when there are upper / lower case.
> 
> This is the facet definition:
> 
> {  
> "size": 0,  
> "facets" : {  
> "location" : {  
> "terms" : {  
> "field" : "location.untouched",  
> "size" : 10,  
> "order" : "term"  
> }  
> }  
> }  
> }
> 
> And this is the response:
> 
> {  
> "took": 0,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 1,  
> "successful": 1,  
> "failed": 0  
> },  
> "hits": {  
> "total": 814,  
> "max\_score": 1,  
> "hits":   
> },  
> "facets": {  
> "location": {  
> "\_type": "terms",  
> "missing": 49,  
> "total": 781,  
> "other": 739,  
> "terms": [  
> {  
> "term": "AR - Little Rock",  
> "count": 2  
> },  
> {  
> "term": "AZ -Phoenix",  
> "count": 3  
> },  
> {  
> "term": "Aberdeen",  
> "count": 1  
> },  
> {  
> "term": "Abu Dhabi",  
> "count": 1  
> },  
> {  
> "term": "Alberta - Calgary",  
> "count": 1  
> },  
> {  
> "term": "Almere",  
> "count": 11  
> },  
> {  
> "term": "Amazonas - Manaus",  
> "count": 1  
> },  
> {  
> "term": "Amsterdam",  
> "count": 18  
> },  
> {  
> "term": "Athens",  
> "count": 1  
> },  
> {  
> "term": "Bangkok",  
> "count": 3  
> }  
> ]  
> }  
> }  
> }
> 
> "AR - Little Rock" should not be the first location.
> 
> Best Regards,  
> Roberto.

--  
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:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [August 19, 2013, 8:02pm UTC](https://discuss.elastic.co/t/term-facet-ordering/13256/3 "2013-08-19T20:02:27Z")

</div>

At first glance, this appears to be correct. But with the assumption that  
location.untouched is a field that is not analyzed at all.

What if you change location.untouched to be lowercased but not tokenized?  
I've applied facets to analyzed fields that included folded case filters,  
and the sorting is in the expected order with case-insensitive collation.

Brian

On Monday, August 19, 2013 7:22:32 AM UTC-4, [roberto.m...@gmail.com](mailto:roberto.m...@gmail.com) wrote:

> Hi,
> 
> I have an issue related to the ordering of the term facets. It seems that  
> the ordering does not work properly when there are upper / lower case.
> 
> This is the facet definition:
> 
> {  
> "size": 0,  
> "facets" : {  
> "location" : {  
> "terms" : {  
> "field" : "location.untouched",  
> "size" : 10,  
> "order" : "term"  
> }  
> }  
> }  
> }
> 
> And this is the response:
> 
> {  
> "took": 0,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 1,  
> "successful": 1,  
> "failed": 0  
> },  
> "hits": {  
> "total": 814,  
> "max\_score": 1,  
> "hits":   
> },  
> "facets": {  
> "location": {  
> "\_type": "terms",  
> "missing": 49,  
> "total": 781,  
> "other": 739,  
> "terms": [  
> {  
> "term": "AR - Little Rock",  
> "count": 2  
> },  
> {  
> "term": "AZ -Phoenix",  
> "count": 3  
> },  
> {  
> "term": "Aberdeen",  
> "count": 1  
> },  
> {  
> "term": "Abu Dhabi",  
> "count": 1  
> },  
> {  
> "term": "Alberta - Calgary",  
> "count": 1  
> },  
> {  
> "term": "Almere",  
> "count": 11  
> },  
> {  
> "term": "Amazonas - Manaus",  
> "count": 1  
> },  
> {  
> "term": "Amsterdam",  
> "count": 18  
> },  
> {  
> "term": "Athens",  
> "count": 1  
> },  
> {  
> "term": "Bangkok",  
> "count": 3  
> }  
> ]  
> }  
> }  
> }
> 
> "AR - Little Rock" should not be the first location.
> 
> Best Regards,  
> Roberto.

--  
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:** ![roberto\_morandeira](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@roberto\_morandeira](https://discuss.elastic.co/u/roberto_morandeira)\
**Post date:** [August 20, 2013, 9:22am UTC](https://discuss.elastic.co/t/term-facet-ordering/13256/4 "2013-08-20T09:22:38Z")

</div>

@simonw: Yes, I assumed that was what was happening.

@InquiringMind: Yes, location.untouched is not analyzed. As you suggested,  
I have modified the field mapping from not\_analized to a custom analyzer  
with lowercase filter and keyword tokenizer, and it's working as I was  
expecting.

Many thanks

Roberto.

El lunes, 19 de agosto de 2013 22:02:27 UTC+2, InquiringMind escribió:

> At first glance, this appears to be correct. But with the assumption that  
> location.untouched is a field that is not analyzed at all.
> 
> What if you change location.untouched to be lowercased but not tokenized?  
> I've applied facets to analyzed fields that included folded case filters,  
> and the sorting is in the expected order with case-insensitive collation.
> 
> Brian
> 
> On Monday, August 19, 2013 7:22:32 AM UTC-4, [roberto.m...@gmail.com](mailto:roberto.m...@gmail.com) wrote:
> 
> > Hi,
> > 
> > I have an issue related to the ordering of the term facets. It seems that  
> > the ordering does not work properly when there are upper / lower case.
> > 
> > This is the facet definition:
> > 
> > {  
> > "size": 0,  
> > "facets" : {  
> > "location" : {  
> > "terms" : {  
> > "field" : "location.untouched",  
> > "size" : 10,  
> > "order" : "term"  
> > }  
> > }  
> > }  
> > }
> > 
> > And this is the response:
> > 
> > {  
> > "took": 0,  
> > "timed\_out": false,  
> > "\_shards": {  
> > "total": 1,  
> > "successful": 1,  
> > "failed": 0  
> > },  
> > "hits": {  
> > "total": 814,  
> > "max\_score": 1,  
> > "hits":   
> > },  
> > "facets": {  
> > "location": {  
> > "\_type": "terms",  
> > "missing": 49,  
> > "total": 781,  
> > "other": 739,  
> > "terms": [  
> > {  
> > "term": "AR - Little Rock",  
> > "count": 2  
> > },  
> > {  
> > "term": "AZ -Phoenix",  
> > "count": 3  
> > },  
> > {  
> > "term": "Aberdeen",  
> > "count": 1  
> > },  
> > {  
> > "term": "Abu Dhabi",  
> > "count": 1  
> > },  
> > {  
> > "term": "Alberta - Calgary",  
> > "count": 1  
> > },  
> > {  
> > "term": "Almere",  
> > "count": 11  
> > },  
> > {  
> > "term": "Amazonas - Manaus",  
> > "count": 1  
> > },  
> > {  
> > "term": "Amsterdam",  
> > "count": 18  
> > },  
> > {  
> > "term": "Athens",  
> > "count": 1  
> > },  
> > {  
> > "term": "Bangkok",  
> > "count": 3  
> > }  
> > ]  
> > }  
> > }  
> > }
> > 
> > "AR - Little Rock" should not be the first location.
> > 
> > Best Regards,  
> > Roberto.

--  
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:20am UTC](https://discuss.elastic.co/t/term-facet-ordering/13256/5 "2017-07-06T02:20:33Z")

</div>


