【问题标题】:Elastic Search sort documents with same score using another field valueElastic Search 使用另一个字段值对具有相同分数的文档进行排序
【发布时间】:2016-07-21 10:57:39
【问题描述】:

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

query: {
                multi_match: {
                        query: "some cooler",
                        type: "most_fields",
                        fields: ["info1", "info2", "info3"]
                }
        }

【问题讨论】:

    标签: sorting elasticsearch


    【解决方案1】:

    你应该检查sort documentation

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

    {
        "query" : {...},
        "sort" : [
            "_score",
            { "likes" : {"order" : "desc"}}
        ]
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多