<?php
require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->build();
// 獲取文檔
$params = [
'index' => 'my_user',
'type' => 'my_user',
'id' => 1
];
// http://localhost:9200/my_user/my_user/1
// $response = $client->get($params);
// print_r($response);
// 搜索文檔
$params = [
'index' => 'my_user',
'type' => 'my_user',
'body' => [
'query' => [
'match' => [
'name' => '張三'
]
]
]
];
$results = $client->search($params);
print_r($results);
echo "<hr/>".PHP_EOL;
$params = [
'index' => 'my_user',
'type' => 'my_user',
'body' => [
'query' => [
'bool' => [
'must' => [
[ 'match' => [ 'name' => '張三' ] ],
]
]
]
]
];
$results = $client->search($params);
print_r($results);
5.elasticsearch-php索引文檔搜索文檔
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.