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

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

littleyuan/elasticsearch
========================

PHP Client for Elasticsearch 7.17.2 Compatible with Alibaba Cloud

7.17.2(2y ago)08Apache-2.0PHPPHP ^7.3 || ^8.0

Since May 12Pushed 2y ago1 watchersCompare

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

READMEChangelogDependencies (7)Versions (2)Used By (0)

[![](https://camo.githubusercontent.com/c9d308aa45784dfd20af1d3b574a1cb3deb3ed3b6d1cb450487814498396a4b4/68747470733a2f2f7777772e656c61737469632e636f2f7374617469632d7265732f696d616765732f656c61737469632d6c6f676f2d3230302e706e67)](https://camo.githubusercontent.com/c9d308aa45784dfd20af1d3b574a1cb3deb3ed3b6d1cb450487814498396a4b4/68747470733a2f2f7777772e656c61737469632e636f2f7374617469632d7265732f696d616765732f656c61737469632d6c6f676f2d3230302e706e67)

elasticsearch-php
=================

[](#elasticsearch-php)

[![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)

Official low-level client for Elasticsearch. Its goal is to provide common ground for all Elasticsearch-related code in PHP; because of this it tries to be opinion-free and very extendable.

To maintain consistency across all the low-level clients (Ruby, Python, etc.), clients accept simple associative arrays as parameters. All parameters, from the URI to the document body, are defined in the associative array.

Starting from version `7.4.0`, all the endpoints (and namespaces) are autogenerated using the [util/GenerateEndpoints.php](https://github.com/elastic/elasticsearch-php/blob/master/util/GenerateEndpoints.php) script. This script reads the [Elasticsearch API specs](https://github.com/elastic/elasticsearch/tree/master/rest-api-spec/src/main/resources/rest-api-spec/api) and generated the PHP classes for all the endpoints.

Starting from version `7.7.0` we included also the [XPack endpoints](https://www.elastic.co/what-is/open-x-pack) of Elasticsearch. These APIs are related to:

- [Cross-cluster replication](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-apis.html)
- [Graph explorer](https://www.elastic.co/guide/en/elasticsearch/reference/current/graph-explore-api.html)
- [Info](https://www.elastic.co/guide/en/elasticsearch/reference/current/info-api.html)
- [Licensing](https://www.elastic.co/guide/en/elasticsearch/reference/current/licensing-apis.html)
- [Machine learning anomaly detection](https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-apis.html)
- [Machine learning data frame analytics](https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-df-analytics-apis.html)
- [Migration](https://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api.html)
- [Reload search analyzers](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-reload-analyzers.html)
- [Rollup](https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-apis.html)
- [Security](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api.html)
- [Snapshot lifecycle management](https://www.elastic.co/guide/en/elasticsearch/reference/current/snapshot-lifecycle-management-api.html)
- [Transform](https://www.elastic.co/guide/en/elasticsearch/reference/current/transform-apis.html)
- [Usage](https://www.elastic.co/guide/en/elasticsearch/reference/current/usage-api.html)
- [Watcher](https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api.html)

Table of Contents
=================

[](#table-of-contents)

- [elasticsearch-php](#elasticsearch-php)
    - [Features](#features)
    - [Version Matrix](#version-matrix)
    - [Compatibility](#compatibility)
    - [Documentation](#documentation)
    - [Installation via Composer](#installation-via-composer)
    - [PHP Version Requirement](#php-version-requirement)
    - [Quickstart](#quickstart)
        - [Index a document](#index-a-document)
        - [Get a document](#get-a-document)
        - [Search for a document](#search-for-a-document)
        - [Delete a document](#delete-a-document)
        - [Delete an index](#delete-an-index)
        - [Create an index](#create-an-index)
- [Unit Testing using Mock a Elastic Client](#unit-testing-using-mock-a-elastic-client)
- [Contributing](#contributing)
- [Wrap up](#wrap-up)
    - [Available Licenses](#available-licenses)
        - [Contributions](#contributions)

Features
--------

[](#features)

- One-to-one mapping with REST API and other language clients
- Configurable, automatic discovery of cluster nodes
- Persistent, Keep-Alive connections (within the lifetime of the script)
- Load balancing (with pluggable selection strategy) across all available nodes. Defaults to round-robin
- Pluggable connection pools to offer different connection strategies
- Generalized, pluggable architecture - most components can be replaced with your own custom class if specialized behavior is required
- Option to use asynchronous future, which enables parallel execution of curl requests to multiple nodes

**Note:** [X-Pack](https://www.elastic.co/what-is/open-x-pack) endpoints are included from elasticsearch-php 7.7+.

Version Matrix
--------------

[](#version-matrix)

Elasticsearch-PHP BranchPHP Version&gt;= 7.16.0, &lt; 8.0.0&gt;= 7.3.0, &lt;= 8.1.99&gt;= 7.12.0, &lt; 8.0.0&gt;= 7.3.0, &lt;= 8.0.99&gt;= 7.11.0, &lt; 8.0.0&gt;= 7.1.0, &lt;= 8.0.99&gt;= 7.0.0, &lt; 7.11.0&gt;= 7.1.0, &lt; 8.0.06.x&gt;= 7.0.0, &lt; 8.0.05.x&gt;= 5.6.6, &lt; 8.0.02.x&gt;= 5.4.0, &lt; 7.0.00.4, 1.x&gt;= 5.3.9, &lt; 7.0.0- If you are using Elasticsearch 7.x, you can use Elasticsearch-PHP 7.x branch.
- If you are using Elasticsearch 6.x, you can use Elasticsearch-PHP 6.x branch.
- If you are using Elasticsearch 5.x, you can use Elasticsearch-PHP 6.x branch.
- If you are using Elasticsearch 1.x or 2.x, prefer using the Elasticsearch-PHP 2.0 branch. The 1.0 branch is compatible however.
- If you are using a version older than 1.0, you must install the `0.4` Elasticsearch-PHP branch. Since ES 0.90.x and below is now EOL, the corresponding `0.4` branch will not receive any more development or bugfixes. Please upgrade.
- You should never use Elasticsearch-PHP Master branch, as it tracks Elasticsearch master and may contain incomplete features or breaks in backwards compatibility. Only use ES-PHP master if you are developing against ES master for some reason.

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

[](#compatibility)

Language clients are forward compatible; meaning that clients support communicating with greater minor versions of Elasticsearch. Elastic language clients are also backwards compatible with lesser supported minor Elasticsearch versions.

Documentation
-------------

[](#documentation)

[Full documentation can be found here.](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html) Docs are stored within the repo under /docs/, so if you see a typo or problem, please submit a PR to fix it!

We also provide a code examples generator for PHP using the `util/GenerateDocExamples.php` script. This command parses the `util/alternative_report.spec.json` file produced from this [JSON specification](https://raw.githubusercontent.com/elastic/built-docs/master/raw/en/elasticsearch/reference/master/alternatives_report.json) and it generates the PHP examples for each digest value. The examples are stored in asciidoc format under `docs/examples` folder.

Installation via Composer
-------------------------

[](#installation-via-composer)

The recommended method to install *Elasticsearch-PHP* is through [Composer](http://getcomposer.org).

1. Add `elasticsearch/elasticsearch` as a dependency in your project's `composer.json` file (change version to suit your version of Elasticsearch, for instance for ES 7.0):

    ```
        {
            "require": {
                "elasticsearch/elasticsearch": "^7.0"
            }
        }
    ```
2. Download and install Composer:

    ```
        curl -s http://getcomposer.org/installer | php
    ```
3. Install your dependencies:

    ```
        php composer.phar install
    ```
4. Require Composer's autoloader

    Composer also prepares an autoload file that's capable of autoloading all the classes in any of the libraries that it downloads. To use it, just add the following line to your code's bootstrap process:

    ```
