ulff / elasticsearch-php-client-bundle
A very simple bundle for integrating Symfony2.x/3.x with Elasticsearch-PHP 5.0
Installs: 12 046
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 4
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.5
- elasticsearch/elasticsearch: ~5.0
- symfony/framework-bundle: ~2.1|~3.0|~4.0
This package is not auto-updated.
Last update: 2025-01-18 20:19:14 UTC
README
Setting up bundle
Version Matrix
You need to match your version of Elasticsearch to the appropriate version of this library.
Step 1: Install bundle
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(), ]; // ... }
Step 2: add bundle configuration
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.
Usage
Client usage
Elasticsearch client is available as a service:
$client = $this->get('ulff_elasticsearch_php_client.client');
Create new index:
$indexParams = new IndexParams('index-name', 'type-name', 'id'); $indexParams->setBody(['someField' => 'some value']); $response = $client->index($indexParams);
Returns IndexResponse object.
Get document:
$getParams = new GetParams('index-name', 'type-name', 'id'); $response = $client->get($getParams);
Returns GetResponse object.
Delete document:
$deleteParams = new DeleteParams('index-name', 'type-name', 'id'); $response = $client->delete($deleteParams);
Returns DeleteResponse object.
Delete by query:
$deleteParams = new DeleteByQueryParams('index-name', 'type-name'); $deleteParams->setBody([ 'query' => [ 'match_all' => new \stdClass(), ] ]); $response = $client->deleteByQuery($deleteParams);
Returns DeleteByQueryResponse object.
Make search query:
$searchParams = new SearchParams('index-name', 'type-name'); $searchParams->setBody([ 'query' => [ 'match' => [ 'someField' => 'some value' ] ] ]); $response = $client->search($searchParams);
Update document:
$updateParams = new UpdateParams('index-name', 'type-name', 'id'); $updateParams->setBody(['someField' => 'some value']); $response = $client->update($updateParams);
Returns UpdateResponse object.
Purger usage
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');
Full documentation:
This bundle is a client for:
Follow the documentation there.
License
This bundle is licensed under the MIT license. Please, see the complete license in the bundle LICENSE
file.