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

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

artpapanyan/elasticsearch
=========================

PHP Client for Elasticsearch

8.4(1y ago)05.7kMITPHPPHP ^7.4 || ^8.0

Since Oct 29Pushed 1y ago1 watchersCompare

[ Source](https://github.com/arthurpapanyan/elasticsearch-php)[ Packagist](https://packagist.org/packages/artpapanyan/elasticsearch)[ RSS](/packages/artpapanyan-elasticsearch/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (14)Versions (2)Used By (0)

 [![Elastic logo](https://github.com/elastic/elasticsearch-py/raw/main/docs/logo-elastic-glyph-color.svg)](https://github.com/elastic/elasticsearch-py/raw/main/docs/logo-elastic-glyph-color.svg)

Elasticsearch PHP client
========================

[](#elasticsearch-php-client)

[![Build status](https://github.com/elastic/elasticsearch-php/workflows/PHP%20test/badge.svg)](https://github.com/elastic/elasticsearch-php/actions) [![Latest Stable Version](https://camo.githubusercontent.com/6021373f1a9c2b32e154ee0df1ad2e56ca30484d17a62a6b420cd6c6a4891b20/68747470733a2f2f706f7365722e707567782e6f72672f656c61737469637365617263682f656c61737469637365617263682f762f737461626c65)](https://packagist.org/packages/elasticsearch/elasticsearch) [![Total Downloads](https://camo.githubusercontent.com/81f97976a5853f51f066cc66fcef9ad4f6463c44dd3c38ff90603fd58e5a7ee3/68747470733a2f2f706f7365722e707567782e6f72672f656c61737469637365617263682f656c61737469637365617263682f646f776e6c6f616473)](https://packagist.org/packages/elasticsearch/elasticsearch)

This is the official PHP client for [Elasticsearch](https://www.elastic.co/elasticsearch/).

**[Download the latest version of Elasticsearch](https://www.elastic.co/downloads/elasticsearch)**or **[sign-up](https://cloud.elastic.co/registration?elektra=en-ess-sign-up-page)****for a free trial of Elastic Cloud**.

Contents
--------

[](#contents)

- [Installation](#installation)
- [Connecting](#connecting)
- [Usage](#usage)
- [Versioning](#versioning)
- [Backward Incompatible Changes](#backward-incompatible-changes-boom)
- [Mock the Elasticsearch client](#mock-the-elasticsearch-client)
- [FAQ](#faq-)
- [Contribute](#contribute-)
- [License](#license-)

---

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

[](#installation)

Refer to the [Installation section](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/getting-started-php.html#_installation)of the getting started documentation.

Connecting
----------

[](#connecting)

Refer to the [Connecting section](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/getting-started-php.html#_connecting)of the getting started documentation.

Usage
-----

[](#usage)

The `elasticsearch-php` client offers 400+ endpoints for interacting with Elasticsearch. A list of all these endpoints is available in the [official documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/rest-apis.html)of Elasticsearch APIs.

Here we reported the basic operation that you can perform with the client: index, search and delete.

- [Creating an index](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/getting-started-php.html#_creating_an_index)
- [Indexing a document](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/getting-started-php.html#_indexing_documents)
- [Getting documents](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/getting-started-php.html#_getting_documents)
- [Searching documents](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/getting-started-php.html#_searching_documents)
- [Updating documents](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/getting-started-php.html#_updating_documents)
- [Deleting documents](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/getting-started-php.html#_deleting_documents)
- [Deleting an index](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/getting-started-php.html#_deleting_an_index)

### Versioning

[](#versioning)

This client is versioned and released alongside Elasticsearch server.

To guarantee compatibility, use the most recent version of this library within the major version of the corresponding Enterprise Search implementation.

For example, for Elasticsearch `7.16`, use `7.16` of this library or above, but not `8.0`.

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

[](#compatibility)

The Elasticsearch client is compatible with currently maintained PHP versions.

Language clients are forward compatible; meaning that clients support communicating with greater or equal minor versions of Elasticsearch without breaking. It does not mean that the client automatically supports new features of newer Elasticsearch versions; it is only possible after a release of a new client version. For example, a 8.12 client version won't automatically support the new features of the 8.13 version of Elasticsearch, the 8.13 client version is required for that. Elasticsearch language clients are only backwards compatible with default distributions and without guarantees made.

Elasticsearch VersionElasticsearch-PHP BranchSupportedmainmain8.x8.x8.x7.x7.x7.17Backward Incompatible Changes 💥
-------------------------------

[](#backward-incompatible-changes-boom)

The 8.0.0 version of `elasticsearch-php` contains a new implementation compared with 7.x. It supports [PSR-7](https://www.php-fig.org/psr/psr-7/) for HTTP messages and [PSR-18](https://www.php-fig.org/psr/psr-18/) for HTTP client communications.

We tried to reduce the BC breaks as much as possible with `7.x` but there are some (big) differences:

- we changed the namespace, now everything is under `Elastic\Elasticsearch`
- we used the [elastic-transport-php](https://github.com/elastic/elastic-transport-php)library for HTTP communications;
- we changed the `Exception` model, using the namespace `Elastic\Elasticsearch\Exception`. All the exceptions extends the `ElasticsearchException` interface, as in 7.x
- we changed the response type of each endpoints using an [Elasticsearch](src/Response/Elasticsearch.php) response class. This class wraps a a [PSR-7](https://www.php-fig.org/psr/psr-7/) response allowing the access of the body response as array or object. This means you can access the API response as in 7.x, no BC break here! 👼
- we changed the `ConnectionPool` in `NodePool`. The `connection` naming was ambigous since the objects are nodes (hosts)

You can have a look at the [BREAKING\_CHANGES](BREAKING_CHANGES.md) file for more information.

Mock the Elasticsearch client
-----------------------------

[](#mock-the-elasticsearch-client)

If you need to mock the Elasticsearch client you just need to mock a [PSR-18](https://www.php-fig.org/psr/psr-18/) HTTP Client.

For instance, you can use the [php-http/mock-client](https://github.com/php-http/mock-client) as follows:

```
use Elastic\Elasticsearch\ClientBuilder;
use Elastic\Elasticsearch\Response\Elasticsearch;
use Http\Mock\Client;
use Nyholm\Psr7\Response;

$mock = new Client(); // This is the mock client

$client = ClientBuilder::create()
    ->setHttpClient($mock)
    ->build();

// This is a PSR-7 response
$response = new Response(
    200,
    [Elasticsearch::HEADER_CHECK => Elasticsearch::PRODUCT_NAME],
    'This is the body!'
);
$mock->addResponse($response);

$result = $client->info(); // Just calling an Elasticsearch endpoint

echo $result->asString(); // This is the body!
```

We are using the `ClientBuilder::setHttpClient()` to set the mock client. You can specify the response that you want to have using the `addResponse($response)` function. As you can see the `$response` is a PSR-7 response object. In this example we used the `Nyholm\Psr7\Response` object from the [nyholm/psr7](https://github.com/Nyholm/psr7) project. If you are using [PHPUnit](https://phpunit.de/) you can even mock the `ResponseInterface` as follows:

```
$response = $this->createMock('Psr\Http\Message\ResponseInterface');
```

**Notice**: we added a special header in the HTTP response. This is the product check header, and it is required for guarantee that `elasticsearch-php` is communicating with an Elasticsearch server 8.0+.

For more information you can read the [Mock client](https://docs.php-http.org/en/latest/clients/mock-client.html)section of PHP-HTTP documentation.

FAQ 🔮
-----

[](#faq-)

### Where do I report issues with the client?

[](#where-do-i-report-issues-with-the-client)

If something is not working as expected, please open an [issue](https://github.com/elastic/elasticsearch-php/issues/new).

### Where else can I go to get help?

[](#where-else-can-i-go-to-get-help)

You can checkout the [Elastic community discuss forums](https://discuss.elastic.co/).

Contribute 🚀
------------

[](#contribute-)

We welcome contributors to the project. Before you begin, some useful info...

- If you want to contribute to this project you need to subscribe to a [Contributor Agreement](https://www.elastic.co/contributor-agreement).
- Before opening a pull request, please create an issue to [discuss the scope of your proposal](https://github.com/elastic/elasticsearch-php/issues).
- If you want to send a PR for version `8.0` please use the `8.0` branch, for `8.1` use the `8.1` branch and so on.
- Never send PR to `master` unless you want to contribute to the development version of the client (`master` represents the next major version).
- Each PR should include a **unit test** using [PHPUnit](https://phpunit.de/). If you are not familiar with PHPUnit you can have a look at the [reference](https://phpunit.readthedocs.io/en/9.5/).

Thanks in advance for your contribution! ❤️

License 📗
---------

[](#license-)

[MIT](LICENSE) © [Elastic](https://www.elastic.co/)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

560d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/af02ceb0819252a33216eeee391512c8a956254a21a3ddea897243b058bd702e?d=identicon)[arthurpapanyan](/maintainers/arthurpapanyan)

---

Top Contributors

[![arthurpapanyan](https://avatars.githubusercontent.com/u/59955639?v=4)](https://github.com/arthurpapanyan "arthurpapanyan (2 commits)")

---

Tags

clientsearchelasticsearchelastic

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[elasticsearch/elasticsearch

PHP Client for Elasticsearch

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

PHP Client for OpenSearch

15024.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)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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