let itemsQuery = new AV.SearchQuery('Items')
itemsQuery.sortBy(new AV.SearchSortBuilder().descending('name','avg', 'last'));

这里其实不用 avg, 但是排序应该是不对, 这里填写 min max avg 会得到不同的排序结果,
并且都不是按照ABC 顺位字母排序
所以估计这里 string 被当成 array 处理了?

我们调查一下。目前,如果你不需要复杂的排序(比如数组)的话,可以直接用 AV.Query 。

update:

The problem with sorting on an analyzed field is not that it uses an analyzer, but that the analyzer tokenizes the string value into multiple tokens, like a bag of words, and Elasticsearch doesn’t know which token to use for sorting.

https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-fields.html3

我建议直接使用 AV.Query

哦哦 可能你理解错了 我这里name字段 就是string而已(见左图) 但是排序结果应该是错误的(见右图),我感觉像是把string 当 array 计算给出的结果

嗯 主要是比较懒 search和 multi condition sort 合写成一个路由了 smile

嗯,可以说目前 SearchQuery 中对 string 类型的字段排序的结果并不符合直觉,详细的原因请参考上面的链接。一个可能的解决方案是将这个字段标记为 not_analyzed,但这可能会影响搜索。目前还请对于此类需求使用 AV.Query。

cc @dennis

那再请教一下 如果是用av.query 因为没有 sortBuilder 是不是多条件排序 用addAscending().addDescending()这样串起来?

不好意思啊 发现一个新问题
AV.SearchQuery 的索引是不是异步创建的,
因为发现新提交的数据, 要过一会才能搜索到, 不是那么实时, 好像延后数秒~数十秒

应用内搜索是这样的,如果需要实时只能用 AV.Query