1
我正在对具有多个字段的文档进行自由文本搜索。当我执行搜索时,我希望在任何标签上都有完美匹配的文档具有更高的评分。有什么办法可以从查询中做到这一点?Elasticsearch查询更喜欢多个字段上的部分匹配的完全匹配
例如,文件有两个字段:label-a
和label-b
,当我执行以下多匹配查询:
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "apple",
"type": "most_fields",
"fields": [
"label-a",
"label-b"
]
}
}
]
}
}
}
我得到下面的结果(仅相关部分):
"hits": [
{
"_index": "salad",
"_type": "fruit",
"_id": "4",
"_score": 0.581694,
"_source": {
"label-a": "apple pie and pizza",
"label-b": "pineapple with apple juice"
}
},
{
"_index": "salad",
"_type": "fruit",
"_id": "2",
"_score": 0.1519148,
"_source": {
"label-a": "grape",
"label-b": "apple"
}
},
{
"_index": "salad",
"_type": "fruit",
"_id": "1",
"_score": 0.038978107,
"_source": {
"label-a": "apple apple apple apple apple apple apple apple apple apple apple apple",
"label-b": "raspberry"
}
},
{
"_index": "salad",
"_type": "fruit",
"_id": "3",
"_score": 0.02250402,
"_source": {
"label-a": "apple pie and pizza",
"label-b": "raspberry"
}
}
]
我想要第二个文档,其值为label-a
的值为grape
,而值为apple
的为label-b
,因为我在搜索该值时得分最高苹果,其中一个标签具有该确切值。无论哪个标签出现确切的术语,这应该工作。
谢谢你的想法!看起来不错。我不想改变索引的映射。 –