[英]Boosting results based on a boolean field
我在各個商店都有大量文章。 其中一些文章是自有品牌文章,在我的 elasticsearch 搜索結果中的排名應該高於其他文章(但是應該顯示自有品牌和非自有品牌。)
我已經嘗試過使用 field_value_factor 的不同方法,但是對於 go 來說,boolean 字段似乎不太好。 我還嘗試了基於 boolean 字段值提升 elasticsearch 結果中的解決方案,但這對我來說效果不佳。 使用 ownBrand 方法的結果仍然比許多非 ownBrand 文章的排名低得多。
指數:
schema: {
articleId: { type: 'text' },
brandId: { type: 'text' },
brandName: { type: 'text' },
countryId: { type: 'text' },
description: { type: 'text' },
isOwnBrand: { type: 'boolean' },
stores: { type: 'keyword' },
},
};
詢問:
query: {
function_score: {
query: {
bool: {
must: {
multi_match: {
query: searchterm,
fields: ['name^5', 'name.ngram'],
fuzziness: 'auto',
prefix_length: 2,
},
},
filter: [{ term: { stores: storeId } }],
},
},
},
},
};
結果應優先考慮頂部 isOwnBrand = true 的字段,同時仍顯示下方 isOwnBrand = false 的相關文章。
我對如何處理這個問題有點迷茫。
您可以使用Field Value factor 。 即使在 boolean 字段上,下面也應該可以正常工作。 試試看
{
"query": {
"function_score": {
"query" {...}, #your normal query as in question
#add below after query
"field_value_factor": {
"field": "isOwnBrand",
"factor": 1.2,
"modifier": "sqrt",
"missing": 1
}
}
}
}
我能想到但尚未測試的一個警告 - 因為false
是0
,所以上面的腳本會將所有帶有 false 的文檔評分為0
分,這會打亂評分。 您可以將 isOwnBrand 設為數字字段並設置從 1 開始的優先級
或者你也可以使用script_score
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.