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

问题描述

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

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

例如,如果我正在搜索短语"Web开发人员",并且如果单词"Web开发人员"一起出现,则与在整个文档中分别出现的"Web"和开发人员"相比,它们将提高5倍.因此,任何包含"Web开发人员"的文档都将首先出现在结果中.

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.

推荐答案

您可以使用,您也可以对它们进行不同的提升.假设您对这两个字词都有常规的匹配查询,无论其位置如何,然后使用提升查询量的词组查询.

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提高了精确词组匹配的重要性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 23:49