I am trying to sort records based on dynamic field names sent to the search API. the d19FilterCriteria object gives me the field name(SortOn) and the order(SortOrder) for sorting. I have used a sort descriptor for this purpose.
var sortDescriptor = new SortDescriptor<MPANStatus>();
// If Field Name is Dynamic
if (d19FilterCriteria.SortOrder == "asc")
{
sortDescriptor.Field(d19FilterCriteria.SortOn, Nest.SortOrder.Ascending);
}
else if (d19FilterCriteria.SortOrder == "desc")
{
sortDescriptor.Field(d19FilterCriteria.SortOn, Nest.SortOrder.Descending);
}
var result = await _elasticClient.SearchAsync<MPANStatus>(s => s
.Index("ampower-mpanstatusindex")
.Skip(skip)
.Size(pageSize)
.Sort(sort =>
{
sort = sortDescriptor;
return sort;
})
While debugging the sort descriptor shows me an object that has a valid value for Name and order

This query returns empty list for this code. Could I know what the issue here is?
result.DebugInformation?