PHP ElasticSearch做搜索实例讲解(2)
从索引中获取文档
$params = [ 'index' => 'articles_index', 'type' => 'articles_type', 'id' => 'articles_1' ]; $res = $client->get($params); print_r($res);
从索引中删除文档
$params = [ 'index' => 'articles_index', 'type' => 'articles_type', 'id' => 'articles_1' ]; $res = $client->delete($params); print_r($res);
删除索引
$params = [ 'index' => 'articles_index' ]; $res = $client->indices()->delete($params); print_r($res);
创建索引
$params['index'] = 'articles_index'; $params['body']['settings']['number_of_shards'] = 2; $params['body']['settings']['number_of_replicas'] = 0; $client->indices()->create($params);
搜索
$params = [ 'index' => 'articles_index', 'type' => 'articles_type', ]; $params['body']['query']['match']['content'] = 'Laravel'; $res = $client->search($params); print_r($res);
以上就是PHP基于ElasticSearch做搜索的详细内容,希望黑区网络整理的内容能够帮助到大家。