我想要來自 Elasticsearch 的過濾結果,其中字串陣列包含特定字串值之一:
這是當前的 json 結果,沒有過濾:
{
"id": 1,
"title": "Title",
"tags": [
"tag filter"
],
},
{
"id": 2,
"title": "Title",
"tags": [
"different tag filter"
],
},
Objectif:僅獲得標簽包含簡單的結果"tag filter"
我做了什么:
$termsQuery = new Terms('POITypes');
$termsQuery->setTerms($terms); // $terms => array("tag filter")
$boolQuery->addMust($termsQuery);
什么dd報告:
SearchController.php on line 90:
Elastica\Query\BoolQuery {#892
#_params: array:1 [
"must" => array:1 [
0 => Elastica\Query\Terms {#893
#_params: array:1 [
"tags" => array:1 [
0 => "tag filter"
]
]
#_rawParams: []
-field: "tags"
}
]
]
#_rawParams: []
}
當我添加此必須過濾此條款要求時,獲得的結果為 0。對于這個簡單的查詢,我自 2 天以來沒有找到任何解決方案……我的代碼有什么問題?
只期望標簽陣列包含我的術語值之一的結果。
uj5u.com熱心網友回復:
將欄位名稱作為 tags.keyword 傳遞。
標簽欄位的型別為“文本”,因此您的查詢試圖將“標簽過濾器”與單個標記[“標簽”、“過濾器”]匹配,您需要將其與完整值匹配。
如果索引是自動創建的,它默認會有關鍵字子欄位,否則你需要創建它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/521196.html
標籤:交响乐弹性搜索弹性束
