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
,因爲我在搜索該值時得分最高蘋果,其中一個標籤具有該確切值。無論哪個標籤出現確切的術語,這應該工作。
謝謝你的想法!看起來不錯。我不想改變索引的映射。 –