在多个字段上排序 [英] Sorting on Multiple Fields
本文介绍了在多个字段上排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Nest支持在多个字段上排序吗?例如,假设我要首先按FieldA升序排序,然后按FieldB降序排序.
Does Nest support sorting on multiple fields? For example, say I want to sort first by FieldA ascending and then by FieldB descending.
我当前的方法如下:
searchDescriptor.Sort(s =>s.OnField("FieldA").Ascending().OnField("FieldB").Descending());
但是"FieldB" .Descending()部分似乎是发送给elasticsearch的唯一排序选项.
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?
推荐答案
您正在同一排序描述符上添加多个字段,这将覆盖先前的值.相反,您需要为每个字段指定一个新的排序描述符:
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()
)
这篇关于在多个字段上排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文