在elasticsearch中对查询或过滤器进行排序

时间:2015-10-01 16:18:11

标签: elasticsearch elasticsearch-net

我正在使用elasticsearch.net客户端。我用分页查询。但它根据排序标准返回文档而不是查询条件。它就像忽略查询只是用于排序。事我想要对所有文档进行排序然后处理查询。我想如果我可以在查询中使用 排序 来解决问题。有什么方法可以做到这一点吗?提前谢谢。

这是代码片段。

    ISearchResponse<Product> response = _elasticClient
                .Search<Product>(p => p
                    .From(request.Pagination.PageIndex - 1)
                    .Size(request.Pagination.ItemCount)
                    .Query(q => q
                        .Bool(b => b
                            .Must(m => m.Term(genderTerm => genderTerm.ProductGenderTypeList, request.BoutiqueFilter.GenderTypeList ?? Enumerable.Empty<string>()))
                            .Should(s => s
                                .Match(m2 => m2
                                    .OnField(on => on.ProductGenderType)
                                    .Query((request.BoutiqueFilter.SortGender == SortGender.None ? String.Empty : ((int)request.BoutiqueFilter.SortGender).ToString()))
                                    .Operator(Operator.And)))))
                    .Sort(sort => request.BoutiqueFilter.SortByPrice == SortByPrice.None
                    ? sort.OnField(onf => onf.Sequence).Ascending()
                    : request.BoutiqueFilter.SortByPrice == SortByPrice.Ascending
                        ? sort.OnField(onf => onf.Price).Ascending()
                        : sort.OnField(onf => onf.Price).Descending()));

0 个答案:

没有答案
相关问题