安装与快速入门
Last updated
Last updated
curl -s http://getcomposer.org/installer | php
php composer.phar install --no-devrequire 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->build();$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id',
'body' => ['testField' => 'abc']
];
$response = $client->index($params);
print_r($response);Array
(
[_index] => my_index
[_type] => my_type
[_id] => my_id
[_version] => 1
[created] => 1
)$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id'
];
$response = $client->get($params);
print_r($response);Array
(
[_index] => my_index
[_type] => my_type
[_id] => my_id
[_version] => 1
[found] => 1
[_source] => Array
(
[testField] => abc
)
)$params = [
'index' => 'my_index',
'type' => 'my_type',
'body' => [
'query' => [
'match' => [
'testField' => 'abc'
]
]
]
];
$response = $client->search($params);
print_r($response);Array
(
[took] => 1
[timed_out] =>
[_shards] => Array
(
[total] => 5
[successful] => 5
[failed] => 0
)
[hits] => Array
(
[total] => 1
[max_score] => 0.30685282
[hits] => Array
(
[0] => Array
(
[_index] => my_index
[_type] => my_type
[_id] => my_id
[_score] => 0.30685282
[_source] => Array
(
[testField] => abc
)
)
)
)
)$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id'
];
$response = $client->delete($params);
print_r($response);Array
(
[found] => 1
[_index] => my_index
[_type] => my_type
[_id] => my_id
[_version] => 2
)$deleteParams = [
'index' => 'my_index'
];
$response = $client->indices()->delete($deleteParams);
print_r($response);Array
(
[acknowledged] => 1
)$params = [
'index' => 'my_index',
'body' => [
'settings' => [
'number_of_shards' => 2,
'number_of_replicas' => 0
]
]
];
$response = $client->indices()->create($params);
print_r($response);Array
(
[acknowledged] => 1
)