V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Reign
V2EX  ›  程序员

ES 中怎样将关联度最高同时按指定字段降序排列?

  •  
  •   Reign · 2018-06-21 08:38:53 +08:00 · 3478 次点击
    这是一个创建于 2135 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目前站内搜索当中,需要的情形如下:用户搜索关键词,比如“摩天轮图片”,ES 进行排序时,需要权衡“关联度”和“点赞数字段”,也就是说将关联度最高同时点赞数最多的图片排在最前面,目的就是尽可能给访客展示关联度最高同时点赞数最多的图片在面,ES 中怎样实现这一排序?

    seaver
        1
    seaver  
       2018-06-21 08:58:35 +08:00
    function score
    yamedie
        2
    yamedie  
       2018-06-21 09:30:32 +08:00
    搜索是后台做的, 是全字匹配还是模糊查询? 有"关键词出现次数"或者"相似度"这种能量化成数字的指标吗? 如果有, 就可以按(指标*权重 + 点赞数*权重)进行降序排序了吧
    pandachow
        3
    pandachow  
       2018-06-21 10:45:28 +08:00
    function score
    loongwang
        4
    loongwang  
       2018-06-21 10:51:07 +08:00 via Android
    GET /xxxxxx-v2/song/_search?explain

    {

      "query": {

        "function_score": {

          "query": {

            "bool": {

              "should": [

                {

                  "match_phrase_prefix": {

                    "name": {

                      "query": "我的一个道姑朋",

                      "boost": 2

                    }

                  }

                },

                {

                  "nested": {

                    "path": "artists",

                    "query": {

                      "bool": {

                        "should": [

                          {

                            "match_phrase": {

                              "artists.name": "我的一个"

                            }

                          }

                        ]

                      }

                    }

                  }

                }

              ]

            }

          },

          "field_value_factor": {

            "field": "score",

            "modifier": "log1p",

            "factor": 0.1

          },

          "boost_mode": "sum"

        }

      },

      "sort": {

        "_score": {

          "order": "desc"

        }

      }

    }

    仅供参考
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3255 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:39 · PVG 20:39 · LAX 05:39 · JFK 08:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.