通過以下代碼存儲了一個新索引。$data = array( array("Name"=>"Norman","Email"=>"[email protected]","Created"=>"2019-12-29 10:28:03","Modified"=>"2020-11-07 01:45:23"), array("Name"=>"Drake","Email"=>"[email protected]","Created"=>"2020-11-08 14:37:00","Modified"=>"2019-08-10 06:42:07"), array("Name"=>"Wynne","Email"=>"[email protected]","Created"=>"2019-05-19 23:30:42","Modified"=>"2019-06-09 08:13:58"), array("Name"=>"Kirsten","Email"=>"[email protected]","Created"=>"2020-01-09 23:34:19","Modified"=>"2020-04-16 10:23:07"), array("Name"=>"Ainsley","Email"=>"[email protected]","Created"=>"2019-01-22 18:14:39","Modified"=>"2019-09-02 18:44:30"), array("Name"=>"Walker","Email"=>"[email protected]","Created"=>"2020-11-05 23:04:46","Modified"=>"2020-01-03 09:29:36"), array("Name"=>"Evelyn","Email"=>"[email protected]","Created"=>"2020-06-28 13:23:09","Modified"=>"2019-04-02 05:41:33"), array("Name"=>"James","Email"=>"[email protected]","Created"=>"2020-04-20 10:15:54","Modified"=>"2020-07-22 12:04:49"), array("Name"=>"Melvin","Email"=>"[email protected]","Created"=>"2020-03-07 05:19:53","Modified"=>"2018-12-30 19:33:29"),);$hosts = ['http://localhost:9200'];$client = ClientBuilder::create()->setHosts($hosts)->build();$params = [ 'index' => 'dummy_data', 'id' => 'my_id', 'body' => ['data' => $data]];$response = $client->index($params);嘗試通過以下方式搜索第一條記錄:$params = [ 'index' => 'dummy_data', 'body' => [ 'query' => [ 'bool' => [ 'must' => [ [ 'match' => [ 'data.Name' => 'Norman' ] ], ], ] ] ]];$results = $client->search($params);問題是它返回查詢僅與第一個匹配的所有記錄。請幫助解決這個問題。
1 回答

胡說叔叔
TA貢獻1804條經驗 獲得超8個贊
我猜你正在使用官方的 Elasticsearch-PHP 庫。在這種情況下,您似乎將所有提供的數據索引為 1 個文檔,其中 id 為“my_id”。這就是為什么您在搜索匹配時獲取整個數據集的原因。
如果您想同時索引多個文檔,您應該查看bulk_index端點。以下是官方示例供參考:
for($i = 0; $i < 100; $i++) {
$params['body'][] = [
'index' => [
'_index' => 'my_index',
]
];
$params['body'][] = [
'my_field' => 'my_value',
'second_field' => 'some more values'
];
}
$responses = $client->bulk($params);
- 1 回答
- 0 關注
- 86 瀏覽
添加回答
舉報
0/150
提交
取消