在pyes和elasticsearch中通过多个参数排序 [英] Sorting by multiple params in pyes and elasticsearch
本文介绍了在pyes和elasticsearch中通过多个参数排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以将一个排序参数传递给pyes中的搜索查询:
I can pass a single sort parameter to the search query in pyes like this:
s = MatchAllQuery()
conn.search(query=Search(s), indexes=["test"], sort='_score')
但是,我需要传递一个额外的参数来对文档进行排序,如下所示:
But I need to pass an extra parameter to sort the docs with the same score, like this:
{
"sort": [
"_score",
{
"extra_param": {
"order": "asc"
}
}
],
"query": {
"term": {
"match_all": {}
}
}
}
我如何在pyes中执行此操作?
How can I do this in pyes?
谢谢
推荐答案
如果您希望结果集中的结果与相同分数按价格排序,将价格附加到排序字符串:
If you'd like the results in the result set with the same score to be ordered by price, append price to the sort string:
s = MatchAllQuery()
conn.search(query=Search(s), indexes=["test"], sort='_score,price')
默认情况下,排序顺序为升序。要将排序顺序附加:asc 或:desc 到排序参数
By default the sort order is ascending. To pass the sort order append :asc or :desc to the sort parameter
s = MatchAllQuery()
conn.search(query=Search(s), indexes=["test"], sort='_score,price:desc')
这篇关于在pyes和elasticsearch中通过多个参数排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文