亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Elasticsearch-php 查詢

Elasticsearch-php 查詢

PHP
30秒到達戰場 2022-10-14 16:02:42
有誰知道彈性搜索-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],

                  ],

                ]

            ],

        ],

    ],

];


查看完整回答
反對 回復 2022-10-14
  • 1 回答
  • 0 關注
  • 183 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號