Create Elasticsearch client using 'config.yml'
# composer.json
"require": {
"caxy/elasticsearch-bundle": "0.0.*"
...
}
and run composer update
command.
# app/AppKernel.php
public function registerBundles()
{
bundles = array(
// ...
new Caxy\Bundle\ElasticsearchBundle\CaxyElasticsearchBundle(),
);
retrun bundles();
}
config.yml
# app/config/config.php
caxy_elasticsearch:
client:
default:
hosts: [ "localhost" ] # Require
named:
class: Your\Elasticsearch\Client
hosts: [ "localhost", "127.0.0.1","localhost:9200", "127.0.0.1:9201" ]
log_path: elasticsearch.log # Optional
log_level: Logger::WARNING # Optional
@see Elasticsearch PHP API -full list of configrations-
Using default settings Elasticsearch client.
# Bundle/Controller/Controller.php
public function fooAction()
{
$es = $this->container->get('caxy_elasticsearch_client');
// or
$es = $this->container->get('caxy_elasticsearch_client.default');
}
Using named settings.
# Bundle/Controller/Controller.php
public function fooAction()
{
$es = $this->container->get('caxy_elasticsearch_client.named');
get_class($es); // Your\Elasticsearch\Client
}