jibe84 / elasticsearch-second-bundle
Symfony2 Bundle on top of elasticsearch/elasticsearch-php, copy of m6web/elasticsearch-bundle
Installs: 12
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 19
Type:symfony-bundle
Requires
- php: >=5.5
- elasticsearch/elasticsearch: ^2.3
Requires (Dev)
- atoum/atoum: ^2.6
- m6web/coke: ~1.2.0
- m6web/symfony2-coding-standard: ~1.2.0
- symfony/config: ^2.3|^3.0
- symfony/dependency-injection: ^2.3|^3.0
- symfony/event-dispatcher: ^2.3|^3.0
- symfony/yaml: ^2.3|^3.0
This package is not auto-updated.
Last update: 2025-03-24 16:51:21 UTC
README
Integration of the Elasticsearch official PHP client within a Symfony Project.
Copy of M6Web/ElasticsearchBundle.
Features
This bundle creates one or more Elasticsearch client services from settings defined in the application configuration.
Usage
Installation
You must first add the bundle to your composer.json
:
"require": { "jibe84/elasticsearch-second-bundle": "dev-master" }
Then register the bundle in your AppKernel
class:
<?php public function registerBundles() { $bundles = array( // ... new M6Web\Bundle\ElasticsearchSecondBundle\M6WebElasticsearchSecondBundle(), ); // ... }
Configuration
In your config.yml
, you can configure one or more Elasticsearch clients:
m6web_elasticsearch: default_client: my_client clients: my_client: hosts: - 'localhost:9200' - 'http://other_host:9201' my_other_client: hosts: - 'other_server:9200'
From this configuration, the bundle will create two services :
m6web_elasticsearch.client.my_client
that will connect to two Elasticsearch instances:localhost
on port 9200 andother_host
on port 9201m6web_elasticsearch.client.my_other_client
that will connect to one Elasticsearch instances:other_server
on port 9200
It will also create m6web_elasticsearch.client.default
which is an alias for m6web_elasticsearch.client.my_client
Additional configuration
Each client can have additional configuration parameters that will be used to instantiate the \Elasticsearch\Client
. Ex:
m6web_elasticsearch: clients: my_client: hosts: - 'https://username:password@localhost:9200' headers: 'Accept-Encoding': ['gzip'] retries: 2 logger: monolog.logger.custom connectionPoolClass: '\Elasticsearch\ConnectionPool\StaticConnectionPool' selectorClass: '\Elasticsearch\ConnectionPool\Selectors\RandomSelector' connectionParams: client: timeout: 3 connect_timeout: 1
Events
The bundle dispatches \M6Web\Bundle\ElasticsearchSecondBundle\EventDispatcher\ElasticsearchEvent
events containing various information about the Elasticsearch requests.
Events are fired with the name m6web.elasticsearch
.
Tests
You can launch the unit tests using:
./vendor/bin/atoum
License
ElasticsearchSecondBundle is licensed under the MIT license.