You need to match your version of Elasticsearch to the appropriate version of this library.
Bundle Version | Elasticsearch Version |
---|---|
2.0 | 5.0 |
1.0 | >= 1.0, ⇐ 5.0 |
Install bundle using composer:
php composer.phar require "ulff/elasticsearch-php-client-bundle:2.0"
Enable the bundle in AppKernel.php:
// app/AppKernel.php
public function registerBundles()
{
$bundles = [
// ...
new Ulff\ElasticsearchPhpClientBundle\UlffElasticsearchPhpClientBundle(),
];
// ...
}
Add following configuration to config.yml:
# app/config/config.yml
ulff_elasticsearch_php_client:
elastic_host: "localhost"
elastic_port: "9200"
Replace values with proper ones.
Elasticsearch client is available as a service:
$client = $this->get('ulff_elasticsearch_php_client.client');
$indexParams = new IndexParams('index-name', 'type-name', 'id');
$indexParams->setBody(['someField' => 'some value']);
$response = $client->index($indexParams);
Returns IndexResponse object.
$getParams = new GetParams('index-name', 'type-name', 'id');
$response = $client->get($getParams);
Returns GetResponse object.
$deleteParams = new DeleteParams('index-name', 'type-name', 'id');
$response = $client->delete($deleteParams);
Returns DeleteResponse object.
$deleteParams = new DeleteByQueryParams('index-name', 'type-name');
$deleteParams->setBody([
'query' => [
'match_all' => new \stdClass(),
]
]);
$response = $client->deleteByQuery($deleteParams);
Returns DeleteByQueryResponse object.
$searchParams = new SearchParams('index-name', 'type-name');
$searchParams->setBody([
'query' => [
'match' => [
'someField' => 'some value'
]
]
]);
$response = $client->search($searchParams);
$updateParams = new UpdateParams('index-name', 'type-name', 'id');
$updateParams->setBody(['someField' => 'some value']);
$response = $client->update($updateParams);
Returns UpdateResponse object.
Bundle offers a possibility to purge whole index (by deleting and recreating empty). This can be useful e.g. for testing purposes.
There is a separate ulff_elasticsearch_php_client.purger
service provided with the bundle.
Following example shows how to purge index:
$purger = $this->get('ulff_elasticsearch_php_client.purger');
$purger->purgeIndex('index_name');
This bundle is a client for:
Follow the documentation there.
This bundle is licensed under the MIT license. Please, see the complete license in the bundle LICENSE
file.