# Sorting on multiple fields

**URL:** <https://discuss.elastic.co/t/sorting-on-multiple-fields/32782>\
**Category:** Elasticsearch\
**Created:** [October 22, 2015, 3:32pm UTC](https://discuss.elastic.co/t/sorting-on-multiple-fields/32782 "2015-10-22T15:32:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![evvo](https://avatars.discourse-cdn.com/v4/letter/e/dfb087/32.png) [@evvo](https://discuss.elastic.co/u/evvo)\
**Post date:** [October 22, 2015, 3:32pm UTC](https://discuss.elastic.co/t/sorting-on-multiple-fields/32782/1 "2015-10-22T15:32:50Z")

</div>

Im attempting to do a sort on multiple fields... if a user chooses to search on date then i sort by date alone...

however for the default (relevance) search i want the sort order to be score descending then date descending if scores are the same for 2 or more results....

but not sure my code is working correctly, the else clause seems to be sorting on score only... when 2 or more scores are the same, the dates are not sorting in descending order, the date descending doesnt seem to take effect

my code is

```
.Sort(srt =>
    {
        if (m_intOrderBy == 0) { return srt.OnField(t => t.ESDateOrderedBy).Descending(); }
        else { return srt.OnField("_score").Descending().OnField(f => f.ESDateOrderedBy).Descending(); }
```

---

<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 5, 2017, 11:43pm UTC](https://discuss.elastic.co/t/sorting-on-multiple-fields/32782/2 "2017-07-05T23:43:11Z")

</div>


