Developed with love by KnpLabs Hire us for your project!
44

ElasticsearchBundle

by M6Web

Integration of the Elasticsearch official PHP client within a Symfony Project

ElasticsearchBundle Build Status

Integration of the Elasticsearch official PHP client within a Symfony Project.

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": {
        "m6web/elasticsearch-bundle": "dev-master"
    }

Then register the bundle in your AppKernel class:

<?php
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new M6Web\Bundle\ElasticsearchBundle\M6WebElasticsearchBundle(),
        );
        // ...
    }

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 and other_host on port 9201
  • m6web_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\ElasticsearchBundle\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

ElasticsearchBundle is licensed under the MIT license.

The MIT License (MIT)

Copyright (c) 2014 M6Web

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
  • composer.json: Support version ^6.0.0 for elasticsearch (#26)
    By Oliboy50, 2 years ago
  • Merge pull request #25 from mojoLyon/bugfix/check-sf-datacollector-var2str-method
    By web-flow, 2 years ago
  • Add method stringifyVariable to use method depending on sf version
    By St├ęphane Reuille, 2 years ago
  • Merge pull request #23 from mojoLyon/fix/datacollector-missing-reset
    By web-flow, 2 years ago
  • Add missing reset method in datacollector
    By St├ęphane Reuille, 2 years ago
  • Merge pull request #19 from M6Web/fix/elastic-statsd-event-duration
    By web-flow, 3 years ago
  • Duration is received as seconds but stored as ms.
    By Gael Millet, 3 years ago
  • Merge pull request #18 from jubianchi/update-atoum
    By web-flow, 3 years ago
  • Update to newer atoum versions
    By jubianchi, 3 years ago
  • Merge pull request #16 from M6Web/feature/es-5.0-client
    By web-flow, 3 years ago
  • Drop tests for php 5.6.
    By , 3 years ago
  • Kick out support for php 5.6
    By b-viguier, 3 years ago
  • Updated elasticsearch version and php requirements
    By b-viguier, 3 years ago
  • Update to elasticsearch client main branch 5.0.x-dev since last release is too old.
    By valentin-claras, 3 years ago
  • Use the new elasticsearch client for version 5.0.
    By valentin-claras, 3 years ago
  • Merge pull request #15 from M6Web/feature/support-connectionParams
    By web-flow, 3 years ago
  • support ClientBuilder->setConnectionParams()
    By Oliboy50, 3 years ago
  • Merge pull request #14 from M6Web/feature/client-builder-class
    By web-flow, 3 years ago
  • Add option to customize client builder class.
    By valentin-claras, 3 years ago
  • Merge pull request #13 from M6Web/feature/customize-client-class
    By web-flow, 3 years ago
  • Add option to customize client class.
    By valentin-claras, 3 years ago
  • Merge pull request #12 from M6Web/feature/random-sticky-and-alive-no-ping
    By web-flow, 3 years ago
  • Remove xdebug from travis.
    By valentin-claras, 3 years ago
  • Add connectionPoolClass and selectorClass option to the configuration.
    By valentin-claras, 3 years ago
  • Add unit tests for RandomStickySelector and StaticAliveNoPingConnectionPool.
    By valentin-claras, 3 years ago
  • Add StaticAliveNoPingConnectionPool.
    By valentin-claras, 3 years ago
  • Add RandomStickySelector.
    By valentin-claras, 3 years ago
  • Merge pull request #9 from gbprod/master
    By mikaelrandy, 4 years ago
  • Set dependencies to use the most recent version
    By gbprod, 4 years ago
  • Remove php5.4 support
    By gbprod, 4 years ago