【问题标题】:In a multi_match query, is it possible to boost a term's relevancy in a similar fashion that it is with field's relevancy?在 multi_match 查询中,是否有可能以与字段相关性类似的方式提高术语的相关性?
【发布时间】:2019-01-22 21:11:51
【问题描述】:

所以我们知道可以通过使用插入符号 (^) 后跟数字来提高字段的相关性,如下所示:

{
    "query": {
        "multi_match": {
            "query": "something of value",
            "fields": [ "name^2", "category" ]
        }
    }
}

但对术语 (query) 应用相同的逻辑并不能提高其相关性:

{
    "query": {
        "multi_match": {
            "query": "something^3 of value",
            "fields": [ "name", "category" ]
        }
    }
}

我想要做的是提升query 的第一个单词,因此希望在fields 的每个字段开头包含该单词的文档优先。

我用span_term (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-term-query.html) 尝试了一些东西,但它不支持multi_match

有什么想法吗?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    简而言之,回答您的问题:不,使用多重匹配查询是不可能的。一种提升词条的方法是查询字符串查询。

    TLDR;

    我认为您对多重匹配查询有误解。

    您可以使用插入符号来提升字段,而不是查询本身。另见issue

    您可以改用Query String Query

    我创建了两个文档

    PUT test/_doc/5
    {
      "name": "Something Blue Something Borrowed Something New",
      "category": "Comedy"
    }
    PUT test/_doc/6
    {
      "name": "There's Something About Mary",
      "category": "Comedy"
    }
    

    搜索,提升词条蓝色

    GET test/_search
    {
        "query": {
            "query_string" : {
                "default_field" : "name",
                "query" : "Something Blue^2"
            }
        }
    }
    

    搜索结果

    {
      "took" : 4,
      "hits" : {
        "total" : 2,
        "max_score" : 1.027436,
        "hits" : [
          {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "5",
            "_score" : 1.027436,
            "_source" : {
              "name" : "Something Blue Something Borrowed Something New",
              "category" : "Comedy"
            }
          },
          {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "6",
            "_score" : 0.7590336,
            "_source" : {
              "name" : "There's Something About Mary",
              "category" : "Comedy"
            }
          }
        ]
      }
    }
    

    如果你问解释 api

    GET test/_doc/5/_explain
    {
        "query": {
            "query_string" : {
                "default_field" : "name",
                "query" : "Something Blue^2"
            }
        }
    }
    

    相关的解释结果

    {
            "value" : 0.5753642,
            "description" : "weight(name:blue in 0) [PerFieldSimilarity], result of:",
            "details" : [
              {
                "value" : 0.5753642,
                "description" : "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
                "details" : [
                  {
                    "value" : 2.0,
                    "description" : "boost",
                    "details" : [ ]
                  },
    ...
    

    【讨论】:

      猜你喜欢
      • 2021-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      • 2012-03-29
      • 2019-12-29
      • 1970-01-01
      • 2016-04-21
      相关资源
      最近更新 更多