Sort multiple dynamic fields

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.

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