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

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

elasticsearch/elasticsearch
===========================

PHP Client for Elasticsearch

v9.3.0(3mo ago)5.3k178.3M—1%969[12 issues](https://github.com/elastic/elasticsearch-php/issues)[3 PRs](https://github.com/elastic/elasticsearch-php/pulls)20MITPHPPHP ^8.1CI passing

Since Sep 24Pushed yesterday453 watchersCompare

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

READMEChangelog (10)Dependencies (14)Versions (206)Used By (20)

 [![Elastic logo](https://github.com/elastic/elasticsearch-py/raw/main/docs/images/logo-elastic-glyph-color.svg)](https://github.com/elastic/elasticsearch-py/raw/main/docs/images/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/).

You can run [Elasticsearch](https://www.elastic.co/elasticsearch) and [Kibana](https://www.elastic.co/kibana) on your local machine using this command:

```
curl -fsSL https://elastic.co/start-local | sh
```

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 500+ 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 `8.16`, use `8.16` of this library or above, but not `9.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 BranchSupportedmainmain9.x9.x9.x8.x8.x8.xBackward Incompatible Changes 💥
-------------------------------

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

The 9.0.0 version of `elasticsearch-php` contains the same architecture of 8.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 avoid BC breaks for `9.x`, here the main changes:

- **Compatibility with Elasticsearch 9.0:** All changes and additions to Elasticsearch APIs for its 9.0 release are reflected in this release.
- **Serverless client merged in:** the `elastic/elasticsearch-serverless` client is being deprecated, and its functionality has been merged back into this client. This should have zero impact on the way the client works by default. If an endpoint is available in serverless, the PHP function will contains a `@group serverless` phpdoc attribute. If you try to use an endpoint that is not available in serverless you will get a `410` HTTP error with a message as follows: "this endpoint exists but is not available when running in serverless mode". The 9.0.0 client can recognize that it is communicating with a serverless instance if you are using a URL managed by Elastic (e.g. `*.elastic.cloud`). If you are using a proxy, the client will be able to recognize that the host is serverless from the first response. Alternatively, you can explicitly indicate that the host is serverless using the `Client::setServerless(true)` function (`false` by default).
- **New transport library with PSR-18 cURL client as default:** we've removed the Guzzle dependency from the client. By default, the built-in cURL-based HTTP client will be used if no other PSR-18 compatible clients are detected. See release [9.0.0](https://github.com/elastic/elastic-transport-php/releases/tag/v9.0.0) of elastic-transport-php.

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. You can refer to the [CONTRIBUTING](CONTRIBUTING.md)guide for more information.

Thanks in advance for your contribution! ❤️

License 📗
---------

[](#license-)

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

###  Health Score

86

—

ExcellentBetter than 100% of packages

Maintenance91

Actively maintained with recent releases

Popularity86

Widely adopted with strong download metrics

Community66

Healthy contributor diversity

Maturity91

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 54.9% 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 ~23 days

Total

198

Last Release

57d ago

Major Versions

v6.8.3 → v8.14.02024-06-12

v6.8.4 → v8.17.12025-03-28

8.17.x-dev → v9.0.02025-04-18

v7.17.3 → v9.1.02025-08-06

v8.19.0 → 9.0.x-dev2025-09-15

PHP version history (10 changes)v0.4.0PHP &gt;=5.3.9

v2.0.0-beta1PHP &gt;=5.4

v5.0.0PHP ^5.6.6|^7.0

v5.1.2PHP ^7.0

v5.1.3PHP ^5.6|^7.0

v7.0.0PHP ^7.1

7.11.x-devPHP ^7.1 || ^8.0

v6.8.0PHP ^7.3 || ^8.0

v8.0.0-alphaPHP ^7.4 || ^8.0

v9.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/75c7c511421feb14316a01d29a7566bd4fdd97147b5a4f3faa5a065f9d0a0193?d=identicon)[ezimuel](/maintainers/ezimuel)

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

---

Top Contributors

[![polyfractal](https://avatars.githubusercontent.com/u/1224228?v=4)](https://github.com/polyfractal "polyfractal (1286 commits)")[![ezimuel](https://avatars.githubusercontent.com/u/475967?v=4)](https://github.com/ezimuel "ezimuel (698 commits)")[![szabosteve](https://avatars.githubusercontent.com/u/22324794?v=4)](https://github.com/szabosteve "szabosteve (72 commits)")[![philkra](https://avatars.githubusercontent.com/u/35487337?v=4)](https://github.com/philkra "philkra (60 commits)")[![miguelgrinberg](https://avatars.githubusercontent.com/u/2715854?v=4)](https://github.com/miguelgrinberg "miguelgrinberg (35 commits)")[![elasticmachine](https://avatars.githubusercontent.com/u/15837671?v=4)](https://github.com/elasticmachine "elasticmachine (26 commits)")[![mhujer](https://avatars.githubusercontent.com/u/353372?v=4)](https://github.com/mhujer "mhujer (25 commits)")[![simplechris](https://avatars.githubusercontent.com/u/520892?v=4)](https://github.com/simplechris "simplechris (17 commits)")[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (14 commits)")[![picandocodigo](https://avatars.githubusercontent.com/u/689327?v=4)](https://github.com/picandocodigo "picandocodigo (13 commits)")[![marciw](https://avatars.githubusercontent.com/u/333176?v=4)](https://github.com/marciw "marciw (9 commits)")[![ketkee-aryamane](https://avatars.githubusercontent.com/u/217762802?v=4)](https://github.com/ketkee-aryamane "ketkee-aryamane (8 commits)")[![afrozenpeach](https://avatars.githubusercontent.com/u/1694214?v=4)](https://github.com/afrozenpeach "afrozenpeach (8 commits)")[![jrodewig](https://avatars.githubusercontent.com/u/40268737?v=4)](https://github.com/jrodewig "jrodewig (7 commits)")[![hkulekci](https://avatars.githubusercontent.com/u/586318?v=4)](https://github.com/hkulekci "hkulekci (6 commits)")[![joelwurtz](https://avatars.githubusercontent.com/u/90466?v=4)](https://github.com/joelwurtz "joelwurtz (6 commits)")[![bezhermoso](https://avatars.githubusercontent.com/u/1437428?v=4)](https://github.com/bezhermoso "bezhermoso (6 commits)")[![pquentin](https://avatars.githubusercontent.com/u/42327?v=4)](https://github.com/pquentin "pquentin (6 commits)")[![abulhol](https://avatars.githubusercontent.com/u/4851778?v=4)](https://github.com/abulhol "abulhol (4 commits)")[![rayward](https://avatars.githubusercontent.com/u/1217111?v=4)](https://github.com/rayward "rayward (4 commits)")

---

Tags

clientelasticsearchphpclientsearchelasticsearchelastic

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

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

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)

PHPackages © 2026

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