pmg / elasticsearch-bundle
An extremely simple Elasticsearch bundle for Symfony
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 7 535
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 11
Forks: 0
Open Issues: 1
Requires
- php: ~7.2
- elasticsearch/elasticsearch: ~2.0|~5.0
- symfony/framework-bundle: ~4.0
Requires (Dev)
- phpunit/phpunit: ~7.5|~8.3
- symfony/browser-kit: ~4.0
- symfony/monolog-bundle: ~3.4
- symfony/phpunit-bridge: ~4.3
- symfony/yaml: ~4.0
README
This is an extremely simple bundle to integrate Elasticsearch into Symfony. It only provides some configuration and the elasticsearch client.
Installation
Grab the bundle with composer:
composer require pmg/elasticsearch-bundle ~1.0
And enable it in your AppKernel
.
<?php // app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = [ // ... new PMG\ElasticsearchBundle\PmgElasticsearchBundle(), ); // ... return $bundles; } // ... }
Configuration
You'll use the pmg_elasticsearch
key in your config.yml
file. The options
are very similar to what is done with with elasticsearch itself. Most of the
options here are null
and use the default set by Elasticsearch\Client
.
You can set up multiple connections:
pmg_elasticsearch: default_client: example clients: example: connection_class: ~ connection_factory_class: ~ connection_pool_class: ~ selector_class: ~ serializer_class: ~ sniff_on_start: ~ hosts: - http://localhost:9200 another: ~
Or just a single client:
pmg_elasticsearch: connection_class: ~ connection_factory_class: ~ connection_pool_class: ~ selector_class: ~ serializer_class: ~ sniff_on_start: ~ hosts: - http://localhost:9200
Services
The pmg_elasticsearch.client
service will always be the default client. Other
clients can be accessed with pmg_elasticsear.{name}.client
.
use Symfony\Component\DependencyInjection\ContainerInterface; /** @var $container ContainerInterface */ $client = $container->get('pmg_elasticsearch.client'); $otherClient = $container->get('pmg_elasticsearch.another.client');