有誰知道彈性搜索-php 示例的好資源,理想情況下涵蓋了使用 MySQL 示例的查詢。我正在為代碼語法和何時使用什么而苦苦掙扎。例如,我想做一個搜索,其中 $name 必須是字段 'business' 的一部分,并且 'country' 匹配 $country$params = [ 'index' => 'xxxxx', 'type' => 'zzzzz', 'body' => [ 'from' => 0, 'size' => $maxResults, 'query' => [ 'bool' => [ 'must' => [ 'match' => ['name' => $searchString], ], 'must' => [ 'match' => ['country' => $country], ], ], ], ],];第一個“必須”似乎被完全忽略了。刪除它將返回完全相同的結果。我搜索了幾個小時。有很多帶有簡單搜索示例的快速初學者教程,但我已經像上面的示例一樣被卡住了一步
1 回答

尚方寶劍之說
TA貢獻1788條經驗 獲得超4個贊
must一個查詢中只能有一個bool,那么所有的約束都必須是must數組的元素。試試這樣:
$params = [
'index' => 'xxxxx',
'type' => 'zzzzz',
'body' => [
'from' => 0,
'size' => $maxResults,
'query' => [
'bool' => [
'must' => [
[
'match' => ['name' => $searchString],
],
[
'match' => ['country' => $country],
],
]
],
],
],
];
- 1 回答
- 0 關注
- 183 瀏覽
添加回答
舉報
0/150
提交
取消