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

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

novaway/elasticsearch-client
============================

\[Discontinued\] A lightweight PHP client for Elasticsearch

6.5.2(7y ago)512.9k7[2 issues](https://github.com/novaway/elasticsearch-client/issues)[2 PRs](https://github.com/novaway/elasticsearch-client/pulls)MITPHPPHP ^7.0CI failing

Since May 4Pushed 4y ago8 watchersCompare

[ Source](https://github.com/novaway/elasticsearch-client)[ Packagist](https://packagist.org/packages/novaway/elasticsearch-client)[ RSS](/packages/novaway-elasticsearch-client/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (11)Versions (26)Used By (0)

Novaway ElasticSearch Client
============================

[](#novaway-elasticsearch-client)

Note : this project is discontinued in favor of the [ElasticsearchBundle](https://github.com/novaway/elasticsearch-bundle), as it was more or less trying to do what elastica does already well

A lightweight PHP 7.0+ client for Elasticsearch, providing features over [Elasticsearch-PHP](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html)

Compatibility
-------------

[](#compatibility)

This branch is tested and compatible with ElasticSearch 6.\*

The compatibility with ElasticSearch 5.\* is supported, and should work, but is to be considered hazardous.

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

[](#installation)

Install using [composer](https://getcomposer.org):

```
$ composer require novaway/elasticsearch-client
```

Usage
-----

[](#usage)

### Create an index

[](#create-an-index)

The first thing you'll need to do to use this library is to instatiate an index. This will be the keystone of the client.

```
$index = new \Novaway\ElasticsearchClient\Index(
	['127.0.0.1:9200'],  	# elasticsearch hosts
	'main_index',				# index name
	[
        'settings' => [
            'number_of_shards' => 3,
            'number_of_replicas' => 2
        ],
        'mappings' => [
            'my_type' => [
                '_source' => [
                    'enabled' => true
                ],
                'properties' => [
                    'first_name' => [
                        'type' => 'string',
                        'analyzer' => 'standard'
                    ],
                    'age' => [
                        'type' => 'integer'
                    ]
                ]
            ]
        ]
    ]
);
```

### Index an object

[](#index-an-object)

In order to be searched, objects should be indexed as a serialized version. In order to be indexed, Object should implement `\Novaway\ElasticsearchClient\Indexable` interface.

By default, objects are serialized with [Elasticsearch-PHP's SmartSerializer](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_serializers.html#_smartserializer), but you can choose to [use a custom serializer](doc/working-with-a-custom-serializer.md).

```
$objectIndexer = new \Novaway\ElasticsearchClient\ObjectIndexer($index);
$objectIndexer->index($object, 'my_type');
```

#### Remove an object from index

[](#remove-an-object-from-index)

To remove an object from the index, the process is still

```
$objectIndexer = new \Novaway\ElasticsearchClient\ObjectIndexer($index);
$objectIndexer->remove($object, 'my_type');

// Alternatively, you can remove an indexed object knowing only it's ID.
$objectIndexer->removeById($objectId, 'my_type');
```

### Search the index

[](#search-the-index)

#### Basic match query

[](#basic-match-query)

First, create a `QueryExecutor`.

```
$queryExecutor = new \Novaway\ElasticsearchClient\QueryExecutor($index);
```

Use the `QueryBuilder` to build your query and execute it.

```
use Novaway\ElasticsearchClient\Query\CombiningFactor;

$queryBody = QueryBuilder::createNew()
					->match('first_name', 'John', CombiningFactor::MUST)
					->getQueryBody()
;
$queryExecutor->execute($queryBody, 'my_type');
```

The `QueryBuilder` allow you to define a limit and an offset for a search result, and choose the minimum score to display.

```
const MIN_SCORE = 0.4;
const OFFSET = 0;
const LIMIT = 10;

$queryBuilder = QueryBuilder::createNew(0, 10, 0.3);
```

#### Advanced Querying

[](#advanced-querying)

This client provide several ways to improve querying :

- Filtering *(missing documentation)*
- [Aggregations](doc/aggregation.md)
- Result Formating *(missing documentation)*

### Clear the index

[](#clear-the-index)

You might want, for some reason, to purge an index. The `reload` method drops and recreates the index.

```
$index->reload();
```

### Hotswapping

[](#hotswapping)

You will want to reindex all your data sometimes.

It is possible to do it without downtime using the hotswap mechanisme

```
$index->hotswapToTmp();
// at that point, all your search request will go to the tmp index, and your create/delete will go to the main index
// when your are done reindexing your data, simply call
$index->hotswapToMain()
```

Recommended usage with Symfony
------------------------------

[](#recommended-usage-with-symfony)

If you are using this library in a symfony project, we recommend to use it as service.

```
# services.yml
parameters:
    myapp.search.myindex.config:
        settings:
            number_of_shards : 1
            number_of_replicas : 1
        mappings:
            my_type:
                _source : { enabled : true }
                properties:
                    first_name:
                        type: string
                        analyzer: standard
                    age:
                        type: integer

services:
    myapp.search.index:
        class: Novaway\ElasticsearchClient\Index
        arguments:
            - ['127.0.0.1:9200'] #define it in the parameter.yml file
            - 'myapp_myindex_%kernel.environment%'
            - 'myapp.search.myindex.config'

    myapp.search.object_indexer:
        class: Novaway\ElasticsearchClient\ObjectIndexer
        arguments:
            - '@myapp.search.index'

    myapp.search.query_executor:
        class: Novaway\ElasticsearchClient\QueryExecutor
        arguments:
            - '@myapp.search.index'
```

Then you'll only have to work with the `myapp.search.object_indexer` and `myapp.search.query_executor` services.

Testing
-------

[](#testing)

A testing environment is provided using a dockerized version of elasticsearch.

Testing is done using the [Atoum](http://atoum.org/) framework for unit testing and the [Behat](http://behat.org/en/latest/) framework for behavior testing.

A `Makefile` provide useful commands for testing, so you can run the full test suite by running :

```
$ make test
```

License
-------

[](#license)

This library is published under [MIT license](LICENSE)

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 51.2% 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 ~28 days

Recently: every ~7 days

Total

25

Last Release

2663d ago

Major Versions

0.1.4 → 1.7.x-dev2017-10-03

1.7.x-dev → 2.3.x-dev2018-08-20

2.3.x-dev → 6.02018-10-11

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/279280?v=4)[Cédric](/maintainers/skwi)[@skwi](https://github.com/skwi)

---

Top Contributors

[![skwi](https://avatars.githubusercontent.com/u/279280?v=4)](https://github.com/skwi "skwi (41 commits)")[![CheapHasz](https://avatars.githubusercontent.com/u/13929571?v=4)](https://github.com/CheapHasz "CheapHasz (34 commits)")[![2BriTo](https://avatars.githubusercontent.com/u/38725731?v=4)](https://github.com/2BriTo "2BriTo (2 commits)")[![delphiki](https://avatars.githubusercontent.com/u/303778?v=4)](https://github.com/delphiki "delphiki (2 commits)")[![Ouark](https://avatars.githubusercontent.com/u/119316?v=4)](https://github.com/Ouark "Ouark (1 commits)")

---

Tags

elasticsearchelasticsearch-phplibraryphpelasticsearch

###  Code Quality

TestsBehat

### Embed Badge

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

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

###  Alternatives

[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[cmsig/seal-symfony-bundle

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

15284.6k11](/packages/cmsig-seal-symfony-bundle)

PHPackages © 2026

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