caxy / elasticsearch-bundle
Symfony Elasticsearch Bundle
Installs: 43
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 24
Forks: 2
Type:symfony-bundle
Requires
- php: >=5.3.2
- elasticsearch/elasticsearch: ~0.4
- symfony/monolog-bundle: 2.3.*
- symfony/symfony: 2.*
This package is auto-updated.
Last update: 2024-10-22 07:18:51 UTC
README
Create Elasticsearch client using 'config.yml'
Installation
composer.json
# composer.json
"require": {
"caxy/elasticsearch-bundle": "0.0.*"
...
}
and run composer update
command.
AppKernel.php
# app/AppKernel.php
public function registerBundles()
{
bundles = array(
// ...
new Caxy\Bundle\ElasticsearchBundle\CaxyElasticsearchBundle(),
);
retrun bundles();
}
Configuration
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
Defaults
@see Elasticsearch PHP API -full list of configrations-
Usage
Get client from service.
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
}