它看起来像你可以做到这一点使用的字段类型token_count
连同field_value_factor
功能评分。
因此,在字段映射中类似以下内容:
"name": {
"type": "string",
"fields": {
"length": {
"type": "token_count",
"analyzer": "standard"
}
}
}
这将使用该字段中的令牌数。如果要使用字符数,可以将分析器从standard
自定义符号化为将每个字符标记化。
然后在查询中:
"function_score": {
...,
"field_value_factor": {
"field": "name.length",
"modifier": "reciprocal"
}
}