PHPackages                             markup/elasticsearch-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. markup/elasticsearch-bundle

ActiveSymfony-bundle[Search &amp; Filtering](/categories/search)

markup/elasticsearch-bundle
===========================

A Symfony bundle providing simple integration with the Elasticsearch SDK, also providing web profiler information.

2.0.0(6y ago)018.8k↓50%MITPHPPHP ^7.1

Since Nov 9Pushed 6y ago4 watchersCompare

[ Source](https://github.com/usemarkup/ElasticsearchBundle)[ Packagist](https://packagist.org/packages/markup/elasticsearch-bundle)[ RSS](/packages/markup-elasticsearch-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (10)Versions (14)Used By (0)

A simple Elasticsearch Symfony bundle, by Markup
================================================

[](#a-simple-elasticsearch-symfony-bundle-by-markup)

[![Build Status](https://camo.githubusercontent.com/518909b6373ae3f3e5ba60e6e2d40d45b7b9c10e76ef669a2f6e45ca2693fcad/68747470733a2f2f7472617669732d63692e6f72672f7573656d61726b75702f456c617374696373656172636842756e646c652e737667)](https://travis-ci.org/usemarkup/ElasticsearchBundle)[![Latest Stable Version](https://camo.githubusercontent.com/d9a9919b37100781cc2b754a36aea22f3858a3e15269f3f1e41ff642436d3543/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61726b75702f656c61737469637365617263682d62756e646c652e737667)](https://packagist.org/packages/markup/elasticsearch-bundle)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

A Symfony bundle providing simple integration with the [Elasticsearch PHP SDK](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html), also providing web profiler information.

Installation
------------

[](#installation)

The Markup Elasticsearch bundle can be installed via [Composer](http://getcomposer.org) by requiring the`markup/elasticsearch-bundle` package in your project's `composer.json`, as well as **specifying the correct version of the Elasticsearch SDK for the version of Elastic Stack you are using** (e.g. use 6.x releases for 6.x releases of Elastic Stack, and 7.x releases for 7.x releases):

```
{
    "require": {
        "markup/elasticsearch-bundle": "^2",
        "elasticsearch/elasticsearch": "^7" //if you are using Elastic Stack 7.x versions
    }
}
```

and adding an instance of `Markup\ElasticsearchBundle\MarkupElasticsearchBundle` to your application's kernel:

```
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        return [
            ...
            new \Markup\ElasticsearchBundle\MarkupElasticsearchBundle(),
        ];
    }
    ...
}
```

Configuration
-------------

[](#configuration)

The configuration options for individual Elasticsearch client services are determined by the [extended configuration](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_configuration.html#_extended_host_configuration) defined by the Elasticsearch PHP SDK. No validation is performed at compile time.

### Sample YAML configuration

[](#sample-yaml-configuration)

In the simplest case, a client service (in this case, `markup_elasticsearch.client.simple`) can be declared by just declaring a client name.

```
markup_elasticsearch:
    clients:
        simple: ~
```

This will set up one connection node for that client, at the default location of `http://localhost:9200/`.

For a more complex case with explicit defined node(s), these can be defined explicitly (creating here a service called `markup_elasticsearch.client.complex`):

```
markup_elasticsearch:
    clients:
        complex:
            nodes:
                - host: 8.8.8.8
                  port: 9201
                  scheme: https
                  user: i_am_a_user
                  pass: i_am_a_super_secret_password
                - host: 10.0.3.4
                  scheme: https
                  user: i_am_another_user
                  pass: pss_dont_tell_i_am_a_password
```

This will define a client with two nodes, one at `https://i_am_a_user:i_am_a_super_secret_password@8.8.8.8:9201/` and one at `https://i_am_another_user:pss_dont_tell_i_am_a_password@10.0.3.4:9200/`.

```
markup_elasticsearch:
    clients:
        simple: ~
    logger: my_logger_service_id
    kibana:
        host: https://my-kibana:5601
        should_link_from_profiler: true
```

This will set up a default client as above, with the logger defined as the provided Symfony logger service ID `my_logger_service_id` (defaulting to `logger`), and the Kibana location (for running queries in [Kibana's Dev Tools interface](https://www.elastic.co/guide/en/kibana/current/devtools-kibana.html) from the Symfony web profiler) set as `https://kibana-host:5601` (and defaulting to `http://localhost:5061`). The link to Kibana within the Symfony web profiler is switched on by setting `should_link_from_profiler` to `true`.

### General settings

[](#general-settings)

```
markup_elasticsearch:
    retries: 2
```

- `retries` You can set the number of retries that the client will make against an Elasticsearch instance. If this number is not specified, the default behaviour is use the number of nodes in the cluster that a client is connecting to.
- `endpoint_closure` Although it's an extremely brittle extension point, the Elasticsearch SDK allows definition of an endpoint closure for providing different logic for resolving endpoints. For details and caveats, see the [documentation for this](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_configuration.html#_set_the_endpoint_closure). A configuration value should be a service that is a `callable` - typically an object with a defined `__invoke` method.

### Connection pools

[](#connection-pools)

You can define connection pools on a per-client basis, either using the `ConnectionPoolInterface` implementations from the Elasticsearch SDK, or a custom connection pool service.

The [built-in connection pools](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_connection_pool.html) are `static_no_ping` (the default), `static`, `simple` and `sniffing`.

```
markup_elasticsearch:
    clients:
        my_client:
            connection_pool: sniffing
```

The above configuration will define a client `my_client` which uses the [in-built sniffing connection pool](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_connection_pool.html#_sniffingconnectionpool).

```
markup_elasticsearch:
    clients:
        my_custom_client:
            connection_pool: my_custom_pool
    custom_connection_pools:
        my_custom_pool: 'acme.my_custom_pool'
```

The above configuration will define a client `my_custom_client` which uses a custom connection pool service `acme.my_custom_pool`.

### Connection selectors

[](#connection-selectors)

You can define [connection selectors](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_selectors.html) on a per-client basis, either using the `SelectorInterface` implementations from the Elasticsearch SDK, or a custom connection selector service.

The built-in connection selectors are `round_robin` (default), `sticky_round_robin` and `random`.

```
markup_elasticsearch:
    clients:
        my_selector_client:
            connection_selector: sticky_round_robin
```

The above configuration will define a client `my_selector_client` which uses the [in-built sticky round-robin](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_selectors.html#_stickyroundrobinselector) connection selector implementation.

```
markup_elasticsearch:
    clients:
        my_custom_selector_client:
            connection_selector: coin_toss
    custom_connection_selectors:
        coin_toss: 'acme.coin_toss_selector'
```

The above configuration will define a client `my_custom_selector_client` which uses a custom connection selector service `acme.coin_toss_selector`.

### Serializers

[](#serializers)

It is not expected that one would need to configure this, but provided for the sake of completeness:

You can define [serializers](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_serializers.html) on a per-client basis, either using the `SerializerInterface` implementations from the Elasticsearch SDK, or a custom serializer service implementing that interface.

The built-in serializers are `smart` (default), `array_to_json` and `everything_to_json`.

```
markup_elasticsearch:
    clients:
        my_serializer_client:
            serializer: everything_to_json
```

The above configuration will define a client `my_serializer_client` which uses the [in-built everything to JSON](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_serializers.html#_everythingtojsonserializer) serializer implementation.

```
markup_elasticsearch:
    clients:
        my_custom_serializer_client:
            serializer: mangled
    custom_serializers:
        mangle: 'acme.mangled_serializer'
```

The above configuration will define a client `my_custom_serializer_client` which uses a custom serializer service `acme.mangled_serializer`.

### HTTP Handlers (RingPHP)

[](#http-handlers-ringphp)

It is not expected that one would need to configure this, but provided for the sake of completeness:

The Elasticsearch SDK uses [RingPHP](https://github.com/guzzle/RingPHP/) HTTP handlers under the hood. Generally the default handler is fine for most cases, but there may be small performance gains etc to be had using a different, or even custom, handler. [The Elasticsearch SDK docs on handlers](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_configuration.html#_configure_the_http_handler) has more information.

The built-in RingPHP-compatible handlers are `default` (default), `single` and `multi`.

```
markup_elasticsearch:
    clients:
        my_handler_client:
            handler: multi
```

The above configuration will define a client `my_handler_client` which uses an in-built handler able to make multiple calls concurrently. (The default handler also does this, but has some logic to determine when to use it.)

```
markup_elasticsearch:
    clients:
        my_custom_handler_client:
            handler: edison
    custom_handlers:
        edison: 'acme.edison_handler'
```

The above configuration will define a client `my_custom_handler_client` which uses a custom RingPHP handler service `acme.edison_handler` that seems to be named after Thomas Edison. For more information about writing a RingPHP HTTP handler, [read the project's documentation on handlers](http://guzzle.readthedocs.org/en/latest/handlers.html).

### Connection Factories

[](#connection-factories)

You can define [connection factories](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_configuration.html#_setting_a_custom_connectionfactory) on a per-client basis using a custom service that implements `ConnectionFactoryInterface` from the Elasticsearch SDK.

There are no in-built connection factories aside from the default implementation.

```
markup_elasticsearch:
    clients:
        my_custom_connection_factory_client:
            connection_factory: my_super_performant_factory
    custom_connection_factories:
        my_super_performant_factory: 'acme.performant_factory'
```

The above configuration will define a client `my_custom_connection_factory_client` which uses a custom connection factory service `acme.performant_factory`.

Usage
-----

[](#usage)

Clients as defined above are provided as instances of \\Elasticsearch\\Client. Usage from that point is as per the [Elasticsearch PHP SDK documentation](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_quickstart.html).

For example, to inject a configured Elasticsearch client into a service at `My\SearchService`, sample YAML configuration might look like:

```
My\SearchService:
    arguments:
        - '@markup_elasticsearch.client.my_client'
```

The client services are defined as private, and therefore require to be injected into e.g. controllers and other services.

Links
-----

[](#links)

- [Elasticsearch PHP SDK on GitHub](https://github.com/elastic/elasticsearch-php)
- [Elasticsearch PHP SDK on elastic.co](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html)
- [Elasticsearch PHP SDK on Packagist](https://packagist.org/packages/elasticsearch/elasticsearch)
- [License (MIT)](https://opensource.org/licenses/MIT)
- [Symfony website](http://symfony.com/)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~4 days

Total

13

Last Release

2467d ago

Major Versions

0.3.1 → 1.0.0-beta12019-01-12

1.0.0 → 2.0.0-alpha2019-07-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c89b3982be4e6cd23e749f617e809147f98aca5f45bf24c3b5195598a4c4bfd?d=identicon)[calumbrodie](/maintainers/calumbrodie)

![](https://www.gravatar.com/avatar/67cf8ed88be79605642722cbc5902206c2e51adf755f70cfff04b2c7e5abc9ce?d=identicon)[shieldo](/maintainers/shieldo)

---

Top Contributors

[![gsdevme](https://avatars.githubusercontent.com/u/319498?v=4)](https://github.com/gsdevme "gsdevme (1 commits)")[![shieldo](https://avatars.githubusercontent.com/u/97280?v=4)](https://github.com/shieldo "shieldo (1 commits)")

---

Tags

clientsearchsymfonybundleelasticsearch

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/markup-elasticsearch-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/markup-elasticsearch-bundle/health.svg)](https://phpackages.com/packages/markup-elasticsearch-bundle)
```

###  Alternatives

[elasticsearch/elasticsearch

PHP Client for Elasticsearch

5.3k178.3M943](/packages/elasticsearch-elasticsearch)[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[jsq/amazon-es-php

Support for using IAM authentication with the official Elasticsearch PHP client

9310.6M13](/packages/jsq-amazon-es-php)[jolicode/elastically

Opinionated Elastica based framework to bootstrap PHP and Elasticsearch implementations.

2571.7M1](/packages/jolicode-elastically)[cmsig/seal-symfony-bundle

An integration of CMS-IG SEAL search abstraction into Symfony Framework.

15195.8k5](/packages/cmsig-seal-symfony-bundle)[rollerworks/search-bundle

RollerworksSearch Bundle

1015.8k1](/packages/rollerworks-search-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
