# Elasticsearch multi-sort possible?

**URL:** <https://discuss.elastic.co/t/elasticsearch-multi-sort-possible/6557>\
**Category:** Elasticsearch\
**Created:** [January 31, 2012, 4:41pm UTC](https://discuss.elastic.co/t/elasticsearch-multi-sort-possible/6557 "2012-01-31T16:41:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rrgrzcool](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rrgrzcool/32/2940_2.png) [@rrgrzcool](https://discuss.elastic.co/u/rrgrzcool)\
**Post date:** [January 31, 2012, 4:41pm UTC](https://discuss.elastic.co/t/elasticsearch-multi-sort-possible/6557/1 "2012-01-31T16:41:47Z")

</div>

I have been tripping over finding a way to run a sort on a set of results by 2 or more attributes. Most likely "\_score" plus something else.

Sample record values:

1. \_score:100, price:50, size:25
2. \_score:100, price:40, size:40
3. \_score:100, price:45, size:30
4. \_score:90, price:48, size:100
5. \_score:90, price:70, size:50

If sorting by \_score (desc) then price (desc), I would expect the ordering:  
1, 3, 2, 5, 4 (results grouped by \_score, subsorted by price desc; 1,2,3 will stay together, as will 4,5, but I would like to affect the ordering within those groups)

If sorting by \_score (desc) then size (desc), I would expect the ordering:  
2, 3, 1, 4, 5

I imagine that this is possible, but I have not yet found the correct method. Can anyone help me out? Thanks!!!

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 1, 2012, 11:16am UTC](https://discuss.elastic.co/t/elasticsearch-multi-sort-possible/6557/2 "2012-02-01T11:16:15Z")

</div>

sort supports providing several (ordered) fields to sort on: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/sort.html).

On Tuesday, January 31, 2012 at 6:41 PM, rrgrzcool wrote:

> I have been tripping over finding a way to run a sort on a set of results by  
> 2 or more attributes. Most likely "\_score" plus something else.
> 
> Sample record values:
> 
> 1. \_score:100, price:50, size:25
> 2. \_score:100, price:40, size:40
> 3. \_score:100, price:45, size:30
> 4. \_score:90, price:48, size:100
> 5. \_score:90, price:70, size:50
> 
> If sorting by \_score (desc) then price (desc), I would expect the ordering:  
> 1, 3, 2, 5, 4 (results grouped by \_score, subsorted by price desc; 1,2,3  
> will stay together, as will 4,5, but I would like to affect the ordering  
> within those groups)
> 
> If sorting by \_score (desc) then size (desc), I would expect the ordering:  
> 2, 3, 1, 4, 5
> 
> I imagine that this is possible, but I have not yet found the correct  
> method. Can anyone help me out? Thanks!!!
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/elasticsearch-multi-sort-possible-tp3703936p3703936.html](http://elasticsearch-users.115913.n3.nabble.com/elasticsearch-multi-sort-possible-tp3703936p3703936.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com) ([http://Nabble.com](http://Nabble.com)).

---

<div class="post-metadata">

**Author:** ![wassem\_a](https://avatars.discourse-cdn.com/v4/letter/w/e9c0ed/32.png) [@wassem\_a](https://discuss.elastic.co/u/wassem_a)\
**Post date:** [February 11, 2013, 12:11pm UTC](https://discuss.elastic.co/t/elasticsearch-multi-sort-possible/6557/3 "2013-02-11T12:11:35Z")

</div>

Try this [http://awesomism.co.uk/536336](http://awesomism.co.uk/536336)

On Wednesday, February 1, 2012 3:16:15 PM UTC+4, kimchy wrote:

> sort supports providing several (ordered) fields to sort on:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/sort.html).
> 
> On Tuesday, January 31, 2012 at 6:41 PM, rrgrzcool wrote:
> 
> I have been tripping over finding a way to run a sort on a set of results  
> by  
> 2 or more attributes. Most likely "\_score" plus something else.
> 
> Sample record values:
> 
> 1. \_score:100, price:50, size:25
> 2. \_score:100, price:40, size:40
> 3. \_score:100, price:45, size:30
> 4. \_score:90, price:48, size:100
> 5. \_score:90, price:70, size:50
> 
> If sorting by \_score (desc) then price (desc), I would expect the ordering:  
> 1, 3, 2, 5, 4 (results grouped by \_score, subsorted by price desc; 1,2,3  
> will stay together, as will 4,5, but I would like to affect the ordering  
> within those groups)
> 
> If sorting by \_score (desc) then size (desc), I would expect the ordering:  
> 2, 3, 1, 4, 5
> 
> I imagine that this is possible, but I have not yet found the correct  
> method. Can anyone help me out? Thanks!!!
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/elasticsearch-multi-sort-possible-tp3703936p3703936.html](http://elasticsearch-users.115913.n3.nabble.com/elasticsearch-multi-sort-possible-tp3703936p3703936.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
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:52am UTC](https://discuss.elastic.co/t/elasticsearch-multi-sort-possible/6557/4 "2017-07-06T02:52:08Z")

</div>


