happyr / elastica-dsn
DSN support to ruflin/Elastica
0.1.1
2020-01-21 16:24 UTC
Requires
- php: ^7.2
- ruflin/elastica: ^6.1 || ^7.0
Requires (Dev)
- nyholm/nsa: ^1.1
- phpunit/phpunit: ^8.2
This package is auto-updated.
Last update: 2024-10-25 02:16:51 UTC
README
This package contains a factory method to create a Elasticsearch client from ruflin/elastica. The factory supports DSN to ease config with a dependency injection container.
Install
composer require happyr/elastica-dsn
Examples
use Happyr\ElasticaDsn\ClientFactory; $client = ClientFactory::create('elasticsearch://localhost'); $client = ClientFactory::create('elasticsearch:?host[localhost]&host[localhost:9201]&host[127.0.0.1:9202]'); $client = ClientFactory::create('elasticsearch://foo:bar@localhost:1234'); $client = ClientFactory::create('elasticsearch://localhost:9201', ['username' => 'foo', 'password' => 'bar']);
If you use Symfony service config:
services: Elastica\Client: factory: 'Happyr\ElasticaDsn\ClientFactory::create' arguments: ['elasticsearch://localhost']
If you want to configure the client even more, you may just get the config array from the ClientFactory
and
instantiate the client yourself.
use Elastica\Client; use Happyr\ElasticaDsn\ClientFactory; $config = ClientFactory::getConfig('elasticsearch://localhost'); // Add more stuff to $config array $client = new Client($config);