设置对应服务与文档索引
//设置服务
$client = new Client('http://localhost:7700', '');
$index = $client->index('movies');
先设置文档索引的字段名称
$index->updateFilterableAttributes(['title']);
待设置任务完成后,打印文档配置
echo json_encode($index->getSettings());
die;
标识设置成功
然后执行文档搜索
$hits = $index->search('Hidden Away', [
'filter' => 'title= "Hidden Away"',
// 'filter' => [
// 'title ="Hidden Away"',
// ],
'attributesToRetrieve' => [
'id',
'title',
],
])
->getHits();
echo json_encode($hits);
die;
filter属性指定搜索字段及内容;attributesToRetrieve属性设置返回的文档的指定字段;执行后搜索结果如图: