Elastic Search 使用另一个字段值对具有相同分数的文档进行排序

vjj*_*jjj 3 sorting elasticsearch

我正在使用弹性搜索,我想根据更高数量的 - “喜欢”字段 - 存储在所有文档中的整数类型,对与下面显示的查询具有相同分数的文档进行排序。代码 -

query: {
                multi_match: {
                        query: "some cooler",
                        type: "most_fields",
                        fields: ["info1", "info2", "info3"]
                }
        }
Run Code Online (Sandbox Code Playgroud)

And*_*e85 8

您应该检查排序文档

只需在 json 排序部分添加一个按分数排序的排序部分,然后是您的自定义字段。

{
    "query" : {...},
    "sort" : [
        "_score",
        { "likes" : {"order" : "desc"}}
    ]
}
Run Code Online (Sandbox Code Playgroud)

评分顺序默认为“desc”。其他字段默认为“asc”,因此如果您需要,您需要为“喜欢”字段定义“desc”顺序。