3

我正在Query String使用Boost Fieldsin Elastic Search 1.7。它工作正常,但在某些情况下,我没有得到预期的结果。
询问:

query
{
   "from": 0,
   "size": 10,
   "explain": true,
   "query": {
      "function_score": {
         "query": {
            "query_string": {
               "query": "account and data",
               "fields": [
                  "title^5"
                  "authors^4",
                  "year^5",
                  "topic^6"
               ],
               "default_operator": "and",
               "analyze_wildcard": true
            }
         },
         "score_mode": "sum",
         "boost_mode": "sum",
         "max_boost": 100
      }
   }
}

样本数据 :

{
   "took": 50,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 4,
      "max_score": 12.833213,
      "hits": [
         {
            "_id": "19850",
            "_score": 12.833213,
            "_source": {
               "ID": "19850",
               "Year": "2010",
               "Title": "account and data :..."
            }
         },
         {
            "_id": "16896",
            "_score": 11.867042,
            "_source": {
               "ID": "16896",
               "Year": "2014",
               "Title": "effectivness of data..."
            }
         },
         {
            "_id": "59862",
            "_score": 9.706333,
            "_source": {
               "ID": "59862",
               "Year": "2007",
               "Title": "best system to..."
            }
         },
         {
            "_id": "18501",
            "_score": 9.685843,
            "_source": {
               "ID": "18501",
               "Year": "2010",
               "Title": "management of..."
            }
         }
      ]
}

我通过使用查询获得了上面的示例数据,这符合预期。但是现在,如果我增加到100 weightyear那么我期望在第 3 位获得第 4 个结果,在第 4 个位置获得第 3 个结果。我尝试了很多东西,但我不知道我做错了什么。

4

1 回答 1

4

仅当查询与您正在提升的字段匹配时才会使用提升,并且它将弹性搜索计算的分数与您定义的提升相乘。在您的查询中,您正在寻找"account and data"并且与任何年份都不匹配,因此不会使用该年份的提升。

您是否要考虑订购年份?如果是这种情况,您可以尝试field_value_factor像这样添加到您的查询中:

"query" : {
    "function_score": {
        "query": { <your query goes here> },
        "field_value_factor": {
            "field": "year"
         }
    }
}

这会将年份与弹性搜索计算的分数相乘,因此它将考虑年份,而无需按年份排序。你可以在这里阅读更多关于它的信息https://www.elastic.co/guide/en/elasticsearch/guide/current/boosting-by-popularity.html

您始终可以使用解释工具来确定弹性搜索是如何得出分数的,从而按该顺序返回结果。https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html

于 2017-07-10T19:53:45.083 回答