# Sorting on multiple fields issue

**URL:** <https://discuss.elastic.co/t/sorting-on-multiple-fields-issue/12598>\
**Category:** Elasticsearch\
**Created:** [July 1, 2013, 11:47am UTC](https://discuss.elastic.co/t/sorting-on-multiple-fields-issue/12598 "2013-07-01T11:47:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baktash\_Ahmed](https://avatars.discourse-cdn.com/v4/letter/b/bc79bd/32.png) [@Baktash\_Ahmed](https://discuss.elastic.co/u/Baktash_Ahmed)\
**Post date:** [July 1, 2013, 11:47am UTC](https://discuss.elastic.co/t/sorting-on-multiple-fields-issue/12598/1 "2013-07-01T11:47:45Z")

</div>

Hi

I am new to ES and recently been moved to another project where I have to  
maintain it temporarily. I have this query that I am running and am doing  
sort of two fields from the same table that are part of ES index. We are  
currently using version 0.90.0 of ES

here is the mapping:

{  
"SomeIndex":{  
"properties":{  
"Classifications":{  
"properties":{  
"Id":{  
"type":"long"  
},  
"Name":{  
"type":"string"  
},  
"NameSortable":{  
"type":"string",  
"index":"not\_analyzed"  
},  
"Type":{  
"type":"long"  
}  
}  
}  
}  
}  
}

There are two types [1, 2]

I want to sort by types first and then by NameSortable. However, my query  
seems to sort only by NameSortable. Please see below for the query:  
{  
"from": 0,  
"size": 15,  
"query": {  
"bool": {  
"must": {  
"term": {  
"State": 3  
}  
},  
"should": [  
{  
"terms": {  
....,  
"minimum\_match": 1  
}  
},  
{  
"terms": {  
....,  
"minimum\_match": 1  
}  
}  
],  
"minimum\_number\_should\_match": 1  
}  
},  
"sort": [  
{  
"Classifications.Type": {}  
},  
{  
"Classifications.NameSortable": {}  
},  
{  
"Date": {  
"order": "desc"  
}  
}  
]  
}

Can some please advise why it is doing the sort in the right order?

Many thanks

ESKFA

--  
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:** ![Baktash\_Ahmed](https://avatars.discourse-cdn.com/v4/letter/b/bc79bd/32.png) [@Baktash\_Ahmed](https://discuss.elastic.co/u/Baktash_Ahmed)\
**Post date:** [July 1, 2013, 4:06pm UTC](https://discuss.elastic.co/t/sorting-on-multiple-fields-issue/12598/2 "2013-07-01T16:06:32Z")

</div>

On Monday, July 1, 2013 12:47:45 PM UTC+1, Baktash Ahmed wrote:

> Hi
> 
> I am new to ES and recently been moved to another project where I have to  
> maintain it temporarily. I have this query that I am running and am doing  
> sort of two fields from the same table that are part of ES index. We are  
> currently using version 0.90.0 of ES
> 
> here is the mapping:
> 
> {  
> "SomeIndex":{  
> "properties":{  
> "Classifications":{  
> "properties":{  
> "Id":{  
> "type":"long"  
> },  
> "Name":{  
> "type":"string"  
> },  
> "NameSortable":{  
> "type":"string",  
> "index":"not\_analyzed"  
> },  
> "Type":{  
> "type":"long"  
> }  
> }  
> }  
> }  
> }  
> }
> 
> There are two types [1, 2]
> 
> I want to sort by types first and then by NameSortable. However, my query  
> seems to sort only by NameSortable. Please see below for the query:  
> {  
> "from": 0,  
> "size": 15,  
> "query": {  
> "bool": {  
> "must": {  
> "term": {  
> "State": 3  
> }  
> },  
> "should": [  
> {  
> "terms": {  
> ....,  
> "minimum\_match": 1  
> }  
> },  
> {  
> "terms": {  
> ....,  
> "minimum\_match": 1  
> }  
> }  
> ],  
> "minimum\_number\_should\_match": 1  
> }  
> },  
> "sort": [  
> {  
> "Classifications.Type": {}  
> },  
> {  
> "Classifications.NameSortable": {}  
> },  
> {  
> "Date": {  
> "order": "desc"  
> }  
> }  
> ]  
> }
> 
> Can some please advise why it is NOT doing the sort in the right order?
> 
> Many thanks
> 
> ESKFA

--  
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:28am UTC](https://discuss.elastic.co/t/sorting-on-multiple-fields-issue/12598/3 "2017-07-06T02:28:46Z")

</div>


