Sorting on Multiple Fields

前端 未结 5 1491
执笔经年
执笔经年 2021-01-04 19:31

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 some

5条回答
  •  -上瘾入骨i
    2021-01-04 19:36

    You are adding multiple fields on the same sort descriptor, which is overriding the previous value. Instead, you need to specify a new sort descriptor for each field:

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

提交回复
热议问题