[英]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.