elasticsearch提高精确短语匹配的重要性 [英] elasticsearch boost importance of exact phrase match

查看:28
本文介绍了elasticsearch提高精确短语匹配的重要性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

elasticsearch 有没有办法提高出现在文档中的确切短语的重要性?

Is there a way in elasticsearch to boost the importance of the exact phrase appearing in the the document?

例如,如果我正在搜索短语web developer",并且如果web developer"这两个词一起出现,则与在整个文档中分别出现的web"和developer"相比,它们会增加 5.因此,任何包含web developer"的文档都会首先出现在结果中.

For example if I was searching for the phrase "web developer" and if the words "web developer" appeared together they would be boosted by 5 compared to "web" and "developer" appearing separately throughout the document. Thereby any document that contained "web developer" together would appear first in the results.

推荐答案

您可以使用 bool 查询,您也可以为它们分配不同的提升.假设您有一个常规的匹配查询词,无论它们的位置如何,然后是具有更高提升的短语查询.

You can combine different queries together using a bool query, and you can assing a different boost to them as well. Let's say you have a regular match query for both the terms, regardless of their positions, and then a phrase query with a higher boost.

类似于以下内容:

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "field": "web developer"
          }
        },
        {
          "match_phrase": {
            "field": "web developer",
            "boost": 5
          }
        }
      ],
      "minimum_number_should_match": 1
    }
  }
}

这篇关于elasticsearch提高精确短语匹配的重要性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆