Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting on Multiple Fields

Tags:

nest

Does Nest support sorting on multiple fields? For example, say I want to sort first by FieldA ascending and then by FieldB descending.

My current approach looks something like this:

searchDescriptor.Sort(s =>s.OnField("FieldA").Ascending().OnField("FieldB").Descending());

But the "FieldB".Descending() part seems to be the only sort option that is sent to elasticsearch.

Does anyone know if there is another way to accomplish this?

like image 768
user3749920 Avatar asked Sep 17 '14 15:09

user3749920


People also ask

Can you sort more than one field in Excel?

Multi-Level Sorting Using Sort Icons Select the column that you want to be sorted last (in this case, select the Sales data first – C1:C13). Click on the Data tab. In the Sort and Filter group, click on the Z to A sorting icon. This will sort the sales data from largest to smallest.

What is multi column sorting?

Multicolumn sorting allows you to sort the fields one after the other. For example, if a user has three different fields rendered in the pivot grid, then it is possible to sort like: OrderBy(field1). ThenBy(field2).


1 Answers

I recent version of Nest the correct way of sortin on multiple fileds would be:

.Sort(s => s
    Field(f => f
        .Field("FieldA")
        .Order(SortOrder.Ascending)
    )
    .Field(f => f
        .Field("FieldB")
        .Order(SortOrder.Ascending)
    )
);
like image 193
Magnus O. Avatar answered Sep 21 '22 15:09

Magnus O.