我使用的與Boost Fields
的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..."
}
}
]
}
我通過使用查詢得到上述樣品的數據,這是按照期望。但是現在,如果我將的year
增加到100,那麼我期望第四名成績在第三名,第三名成績在第四名。我嘗試了很多東西,但我不知道我做錯了什麼。
我是否需要添加所有字段,無論我想要考慮訂購? –
您需要在訂購時添加您想要考慮的字段。但是'field_value_factor'' field'屬性只需要一個字段。如果你想使它成爲兩個字段的組合並添加自定義邏輯,你應該使用'script_score'來代替這裏提到的https://www.elastic.co/guide/en/elasticsearch/guide/current/function-score -query.html –
如果這解決了您的問題,請記住將答案標記爲已接受。 –