annielong

es 分词后能控制分词的权重值吗?

  •  
  •   annielong · Dec 7, 2020 · 6926 views
    This topic created in 2016 days ago, the information mentioned may be changed or developed.
    如查询“办理会员卡”,会分成“办理”、“会员卡”两个分词进行查询,“办理”可能会查询到“办理退货”,有没有什么方法可以优先查询“会员卡”这个分词。目前想到的方案是程序加关键字,先根据查询内容在 es 里面分词,然后拿分词在程序中进行关键字匹配,然后拿关键字去查询。
    3 replies    2020-12-08 07:42:28 +08:00
    zsl199512101234
        2
    zsl199512101234  
       Dec 7, 2020   ❤️ 1
    用不着的感觉,排序的时候词间距和连续性设置下加权就可以把办理... 会员卡...这种排到前面去了
    wukangave
        3
    wukangave  
       Dec 8, 2020   ❤️ 1
    可以给文档加关键字和权重,查询的时候给文档打高分。比如建立索引的时候加如下 fields:
    "keywords": {"type": "nested", "properties":{"keywords": "keyword", "weight": "long"}}
    查询的时候用 function score query 给文档打分:
    "function_score": {"functions": [{"field": "keywords.weight"}], "query":{"match": {"keywords.keywords": "会员卡"}}}
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   977 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 19:26 · PVG 03:26 · LAX 12:26 · JFK 15:26
    ♥ Do have faith in what you're doing.