PHPackages                             nervetattoo/elasticsearch - 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. nervetattoo/elasticsearch

ActiveLibrary[Search &amp; Filtering](/categories/search)

nervetattoo/elasticsearch
=========================

ElasticSearch client for PHP 5.3

v2.4.1(11y ago)342190.1k↓29.9%93[16 issues](https://github.com/nervetattoo/elasticsearch/issues)[4 PRs](https://github.com/nervetattoo/elasticsearch/pulls)1MITPHPPHP &gt;=5.3.0

Since Jun 24Pushed 3y ago23 watchersCompare

[ Source](https://github.com/nervetattoo/elasticsearch)[ Packagist](https://packagist.org/packages/nervetattoo/elasticsearch)[ Docs](http://github.com/nervetattoo/elasticsearch)[ RSS](/packages/nervetattoo-elasticsearch/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (11)Used By (1)

[![Build Status](https://camo.githubusercontent.com/7905f5c90b9c63e72967d5d534eb40a6488e7b2a39551c4057a1cd796fb9e6a0/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6e65727665746174746f6f2f656c61737469637365617263682e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/nervetattoo/elasticsearch)

ElasticSearch PHP client
========================

[](#elasticsearch-php-client)

ElasticSearch is a distributed lucene powered search indexing, this is a PHP client for it

Usage
-----

[](#usage)

### Initial setup

[](#initial-setup)

1. Install composer. `curl -s http://getcomposer.org/installer | php`
2. Create `composer.json` containing:

    ```
    {
        "require" : {
            "nervetattoo/elasticsearch" : ">=2.0"
        }
    }
    ```
3. Run `./composer.phar install`
4. Keep up-to-date: `./composer.phar update`

### Indexing and searching

[](#indexing-and-searching)

```
require_once __DIR__ . '/vendor/autoload.php';

use \ElasticSearch\Client;
// The recommended way to go about things is to use an environment variable called ELASTICSEARCH_URL
$es = Client::connection();

// Alternatively you can use dsn string
$es = Client::connection('http://127.0.0.1:9200/myindex/mytype');

$es->index(array('title' => 'My cool document'), $id);
$es->get($id);
$es->search('title:cool');
```

### Creating mapping

[](#creating-mapping)

```
$es->map(array(
    'title' => array(
        'type' => 'string',
	'index' => 'analyzed'
    )
));
```

### Search multiple indexes or types

[](#search-multiple-indexes-or-types)

```
$results = $es
    ->setIndex(array("one", "two"))
    ->setType(array("mytype", "other-type"))
    ->search('title:cool');
```

### Using the Query DSL

[](#using-the-query-dsl)

```
$es->search(array(
    'query' => array(
        'term' => array('title' => 'cool')
    )
);
```

### Provide configuration as array

[](#provide-configuration-as-array)

Using an array for configuration also works

```
$es = Client::connection(array(
    'servers' => '127.0.0.1:9200',
    'protocol' => 'http',
    'index' => 'myindex',
    'type' => 'mytype'
));
```

### Support for Routing

[](#support-for-routing)

```
$document = array(
    'title' => 'My routed document',
    'user_id' => '42'
);
$es->index($document, $id, array('routing' => $document['user_id']));
$es->search('title:routed', array('routing' => '42'));
```

### Support for Bulking

[](#support-for-bulking)

```
$document = array(
    'title' => 'My bulked entry',
    'user_id' => '43'
);
$es->beginBulk();
$es->index($document, $id, array('routing' => $document['user_id']));
$es->delete(2);
$es->delete(3);
$es->commitBulk();

$es->createBulk()
    ->delete(4)
    ->index($document, $id, 'myIndex', 'myType', array('parent' => $parentId));
    ->delete(5)
    ->delete(6)
    ->commit();
```

### Usage as a service in Symfony2

[](#usage-as-a-service-in-symfony2)

In order to use the Dependency Injection to inject the client as a service, you'll have to define it before. So in your bundle's services.yml file you can put something like this :

```
    your_bundle.elastic_transport:
        class: ElasticSearch\Transport\HTTP
        arguments:
            - localhost
            - 9200
            - 60

    your_bundle.elastic_client:
        class: ElasticSearch\Client
        arguments:
            - @your_bundle.elastic_transport
```

To make Symfony2 recognize the `ElasticSearch` namespace, you'll have to register it. So in your `app/autoload.php` make sure your have :

```
// ...

$loader->registerNamespaces(array(
    // ...
    'ElasticSearch' => __DIR__.'/path/to/your/vendor/nervetattoo/elasticsearch/src',
));
```

Then, you can get your client via the service container and use it like usual. For example, in your controller you can do this :

```
class FooController extends Controller
{
    // ...

    public function barAction()
    {
        // ...
        $es = $this->get('your_bundle.elastic_client');
        $results = $es
            ->setIndex(array("one", "two"))
            ->setType(array("mytype", "other-type"))
            ->search('title:cool');
    }
}
```

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity54

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 71.1% 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 ~154 days

Recently: every ~175 days

Total

6

Last Release

4302d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e817a8e16a540ea8dd73f63a8a88c22dfb1e6413b914a075cd7b2f26798171b?d=identicon)[nervetattoo](/maintainers/nervetattoo)

---

Top Contributors

[![nervetattoo](https://avatars.githubusercontent.com/u/45449?v=4)](https://github.com/nervetattoo "nervetattoo (81 commits)")[![fivetide](https://avatars.githubusercontent.com/u/2804586?v=4)](https://github.com/fivetide "fivetide (7 commits)")[![jclg](https://avatars.githubusercontent.com/u/645802?v=4)](https://github.com/jclg "jclg (7 commits)")[![tbjers](https://avatars.githubusercontent.com/u/1117052?v=4)](https://github.com/tbjers "tbjers (4 commits)")[![gwissem-mention](https://avatars.githubusercontent.com/u/3584016?v=4)](https://github.com/gwissem-mention "gwissem-mention (3 commits)")[![armax15](https://avatars.githubusercontent.com/u/33004296?v=4)](https://github.com/armax15 "armax15 (2 commits)")[![josewilker](https://avatars.githubusercontent.com/u/226850?v=4)](https://github.com/josewilker "josewilker (2 commits)")[![dnavre](https://avatars.githubusercontent.com/u/341914?v=4)](https://github.com/dnavre "dnavre (1 commits)")[![henriquemoody](https://avatars.githubusercontent.com/u/154023?v=4)](https://github.com/henriquemoody "henriquemoody (1 commits)")[![KmeCnin](https://avatars.githubusercontent.com/u/6616300?v=4)](https://github.com/KmeCnin "KmeCnin (1 commits)")[![moos3](https://avatars.githubusercontent.com/u/5654?v=4)](https://github.com/moos3 "moos3 (1 commits)")[![boggibill](https://avatars.githubusercontent.com/u/1745462?v=4)](https://github.com/boggibill "boggibill (1 commits)")[![pedropenduko](https://avatars.githubusercontent.com/u/311849?v=4)](https://github.com/pedropenduko "pedropenduko (1 commits)")[![printercu](https://avatars.githubusercontent.com/u/1144890?v=4)](https://github.com/printercu "printercu (1 commits)")[![jamescarr](https://avatars.githubusercontent.com/u/45389?v=4)](https://github.com/jamescarr "jamescarr (1 commits)")

---

Tags

clientelasticsearch

### Embed Badge

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

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

###  Alternatives

[elasticsearch/elasticsearch

PHP Client for Elasticsearch

5.3k178.3M943](/packages/elasticsearch-elasticsearch)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15224.3M65](/packages/opensearch-project-opensearch-php)[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)[babenkoivan/elastic-client

The official PHP Elasticsearch client integrated with Laravel

544.0M6](/packages/babenkoivan-elastic-client)[babenkoivan/elastic-adapter

Adapter for official PHP Elasticsearch client

404.0M9](/packages/babenkoivan-elastic-adapter)

PHPackages © 2026

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