caxy/elasticsearch-bundle

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Symfony Elasticsearch Bundle

Installs: 39

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 24

Forks: 2

Type:symfony-bundle

0.0.1 2013-10-30 14:42 UTC

This package is auto-updated.

Last update: 2021-10-22 00:50:19 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
}

Client

@see elasticsearch/elasticsearch web site or Documentation