# Sort multiple dynamic fields

**URL:** <https://discuss.elastic.co/t/sort-multiple-dynamic-fields/87684>\
**Category:** Elasticsearch\
**Created:** [May 31, 2017, 7:39am UTC](https://discuss.elastic.co/t/sort-multiple-dynamic-fields/87684 "2017-05-31T07:39:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkthetechie](https://avatars.discourse-cdn.com/v4/letter/j/f08c70/32.png) [@jkthetechie](https://discuss.elastic.co/u/jkthetechie)\
**Post date:** [May 31, 2017, 7:39am UTC](https://discuss.elastic.co/t/sort-multiple-dynamic-fields/87684/1 "2017-05-31T07:39:15Z")

</div>

Need to sort the a search result. Sorting to be done on multiple fields which are passed dynamically.

My Search query is as below.  
searchResult = \_client.Search(x =\> x  
.Index(\_commandFields.IndexName.ToLower())  
.Type(\_commandFields.Type)  
.Query(p =\> +\_commandFields.Query)  
.Size(\_commandFields.Limit)  
.Preference(\_commandFields.ReadPreference.GetDescription())  
.Scroll(\_scrollExpiryTime));

I have List\<Nest.Sort\> list which are the sortable fields.  
List lstsort = new List();  
lstsort.Add( new SortField { Field = "field1", Order = SortOrder.Descending });  
lstsort.Add( new SortField { Field = "field2", Order = SortOrder.Descending });  
lstsort.Add( new SortField { Field = "field3", Order = SortOrder.Descending });  
the above three fields (field1, field2, field3) are dynamic.

How to add this in the search request so that searchResult is in the sorted order.

---

<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:** [June 28, 2017, 7:39am UTC](https://discuss.elastic.co/t/sort-multiple-dynamic-fields/87684/2 "2017-06-28T07:39:27Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
