我是elasticsearch的新手,在用多個關鍵詞搜索所有欄位時遇到了一個問題。例如,如果我搜索我的所有欄位的術語。foo 我得到了所有的結果。
但是如果我在所有欄位中搜索foo bar,它只回傳一個欄位中含有foo和bar的結果,而我知道在一個欄位中有foo的專案,在另一個欄位中有bar。
如果我在所有欄位中搜索foo "bar",它將正確作業并回傳所有欄位的所有結果,但真的不想嘗試向用戶解釋第二個術語的用戶引號。
有人知道我在哪里出了問題嗎?
查詢:
{
"查詢"。{
"bool": {
"必須"。{
"query_string": {
"欄位": ["heading, title, content, call_number"],
"查詢": "foo bar",
"default_operator": "和"
}
}
}
}
}
uj5u.com熱心網友回復:
你要找的是combined_fields搜索查詢
combined_fields查詢支持搜索多個文本欄位,就像它們的內容被索引到一個組合欄位中一樣。readmore
{
"query": {
"combined_fields": {
"查詢": "foo bar",
"欄位": [
"標題",
"標題",
"內容",
"來電號碼"
],
"操作者": "和"
}
}
}
uj5u.com熱心網友回復:
你可以使用multi_match with cross_fields>型別。試試下面的查詢
{
"查詢"。{
"multi_match" : {
"查詢": "foo bar",
"型別": "cross_fields",
"欄位": ["標題", "題目"]
}
}
}
搜索結果是:
"hits": [
{
"_index": "69109590",
"_型別": "_doc",
"_id": "2",
"_score": 0.2876821,
"_source": {
"標題": "酒吧"
}
},
{
"_index": "69109590",
"_型別": "_doc",
"_id": "1",
"_score": 0.2876821,
"_source": {
"標題": "foo"
}
}
]
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/315412.html
標籤:
