# Sorting

**URL:** <https://discuss.elastic.co/t/sorting/4585>\
**Category:** Elasticsearch\
**Created:** [June 9, 2011, 8:31am UTC](https://discuss.elastic.co/t/sorting/4585 "2011-06-09T08:31:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_Kriesten](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@Jan\_Kriesten](https://discuss.elastic.co/u/Jan_Kriesten)\
**Post date:** [June 9, 2011, 8:31am UTC](https://discuss.elastic.co/t/sorting/4585/1 "2011-06-09T08:31:20Z")

</div>

Hi,

is there a way to have elasticsearch sort based on dependend  
field-values instead of fields? Given:

attr : {  
"name" : "filename",  
"value" : "myFile.doc"  
}

attr : {  
"name" : "mimetype",  
"value" : "application/msword"  
}

attr : {  
"name" : "mimetype",  
"value" : "text/html"  
}

Sorting should happen on the value-field of all attr with name="mimetype".

Is there a way to do this?

Best regards, --- Jan.

---

<div class="post-metadata">

**Author:** ![Ludovic\_Levesque](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ludovic_levesque/32/3031_2.png) [@Ludovic\_Levesque](https://discuss.elastic.co/u/Ludovic_Levesque)\
**Post date:** [June 9, 2011, 8:36am UTC](https://discuss.elastic.co/t/sorting/4585/2 "2011-06-09T08:36:24Z")

</div>

Hi,

with a custom\_score and some coding you can achieve this, but it can  
have strong impact on performance if you need to process \_source to  
sort documents.

If you have only mimetype attribute by document and you know you need  
to sort on this value, I think it's better to directly put value in  
another field to have direct sort.

Ludo

On Thu, Jun 9, 2011 at 10:31 AM, Jan Kriesten  
[kriesten@mail.footprint.de](mailto:kriesten@mail.footprint.de) wrote:

> Hi,
> 
> is there a way to have elasticsearch sort based on dependend  
> field-values instead of fields? Given:
> 
> attr : {  
> "name" : "filename",  
> "value" : "myFile.doc"  
> }
> 
> attr : {  
> "name" : "mimetype",  
> "value" : "application/msword"  
> }
> 
> attr : {  
> "name" : "mimetype",  
> "value" : "text/html"  
> }
> 
> Sorting should happen on the value-field of all attr with name="mimetype".
> 
> Is there a way to do this?
> 
> Best regards, --- Jan.

---

<div class="post-metadata">

**Author:** ![Jan\_Kriesten](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@Jan\_Kriesten](https://discuss.elastic.co/u/Jan_Kriesten)\
**Post date:** [June 9, 2011, 8:49am UTC](https://discuss.elastic.co/t/sorting/4585/3 "2011-06-09T08:49:10Z")

</div>

Hi Ludo,

thanks for your quick response.

There are many different attributes for documents and sorting needs to  
be very flexible. So distinct fields are no option.

Given that sorting could happen on different attr (first: mimetype,  
second: filename), that could easily get very complex. Defining a script  
for the score and have multiple attr for sorting seems like a bad idea...

Best regards, --- Jan.

---

<div class="post-metadata">

**Author:** ![fashionalwallet](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@fashionalwallet](https://discuss.elastic.co/u/fashionalwallet)\
**Post date:** [June 9, 2011, 8:53am UTC](https://discuss.elastic.co/t/sorting/4585/4 "2011-06-09T08:53:13Z")

</div>

- deleted -

---

<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:04am UTC](https://discuss.elastic.co/t/sorting/4585/5 "2017-07-06T04:04:23Z")

</div>

Closed on July 6, 2017, 4:04am UTC


