• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Reign
V2EX  ›  程序员

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

  •  
  •   Reign · Jun 21, 2018 · 4343 views
    This topic created in 2918 days ago, the information mentioned may be changed or developed.

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

    seaver
        1
    seaver  
       Jun 21, 2018
    function score
    yamedie
        2
    yamedie  
       Jun 21, 2018
    搜索是后台做的, 是全字匹配还是模糊查询? 有"关键词出现次数"或者"相似度"这种能量化成数字的指标吗? 如果有, 就可以按(指标*权重 + 点赞数*权重)进行降序排序了吧
    xxm459259
        3
    xxm459259  
       Jun 21, 2018
    function score
    loongwang
        4
    loongwang  
       Jun 21, 2018 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"

        }

      }

    }

    仅供参考
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5644 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 03:38 · PVG 11:38 · LAX 20:38 · JFK 23:38
    ♥ Do have faith in what you're doing.