【问题标题】:Python Elasticsearch DSL: how to sort by score in descending order?Python Elasticsearch DSL:如何按分数降序排序?
【发布时间】:2021-12-13 17:55:51
【问题描述】:

我有一个简单的查询:

Search().filter(
    "multi_match",
    fields=['name', 'description'],
    query='something',
    fuzziness="AUTO",
)
.sort("_score")

如何更改排序顺序?

我试过了: .sort("-_score") 返回错误:Sorting by '-_score' is not allowed.

【问题讨论】:

    标签: python elasticsearch elasticsearch-dsl


    【解决方案1】:

    根据documentation,你试过用字典指定吗?

    Search().filter(
        "multi_match",
        fields=['name', 'description'],
        query='something',
        fuzziness="AUTO",
    )
    .sort({"_score": {"order": "desc"}})
    

    【讨论】:

      猜你喜欢
      • 2017-12-26
      • 1970-01-01
      • 1970-01-01
      • 2022-10-12
      • 2017-08-06
      • 2022-01-09
      • 2023-03-12
      • 1970-01-01
      • 2018-12-26
      相关资源
      最近更新 更多