[英]Elastic search apply boost only for certain documents based on their field value
以下是我的索引文檔:
{
"id": 123,
"details": {
"boostType": "Type1",
"boostFactor": 1.00022
}
}
{
"id": 456,
"details": {
"boostType": "Type2",
"boostFactor": 1.00022
}
}
因此,我只想將 boost 應用於具有boostType1
的文檔,並且 boost 值為1.00022
。 下面是我的查詢,但它適用於所有文檔,我只希望它適用於某些boostType
。 我試過這樣做:
{
"query": {
"function_score": {
"boost_mode": "sum",
"functions": [
{
"field_value_factor": {
"field": "details.boostFactor",
"factor": 1,
"missing": 1
}
}
]
}
}
}
函數接受額外的filter
object,請在此處閱讀: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.ZFC35FDC70D5FC67D239883A822應該適合您。
{
"query": {
"function_score": {
"boost_mode": "sum",
"functions": [
{
"filter": {
"term": {
"details.boostType": "Type1"
}
},
"field_value_factor": {
"field": "details.boostFactor",
"factor": 1,
"missing": 1
}
}
]
}
}
}
請注意,我已將boostType
映射為keyword
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.