2017 © Pedro Peláez
 

library elasticsearch

PHP Client for Elasticsearch

image

elasticsearch/elasticsearch

PHP Client for Elasticsearch

  • Wednesday, May 16, 2018
  • by polyfractal
  • Repository
  • 301 Watchers
  • 2489 Stars
  • 12,415,743 Installations
  • PHP
  • 443 Dependents
  • 55 Suggesters
  • 559 Forks
  • 68 Open issues
  • 66 Versions
  • 10 % Grown

The README.md

Elastic logo , (*1)

Elasticsearch PHP client

Build status Latest Stable Version Total Downloads, (*2)

This is the official PHP client for Elasticsearch., (*3)

Download the latest version of Elasticsearch or sign-up for a free trial of Elastic Cloud., (*4)

Contents


Installation

Refer to the Installation section of the getting started documentation., (*5)

Connecting

Refer to the Connecting section of the getting started documentation., (*6)

Usage

The elasticsearch-php client offers 400+ endpoints for interacting with Elasticsearch. A list of all these endpoints is available in the official documentation of Elasticsearch APIs., (*7)

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

Versioning

This client is versioned and released alongside Elasticsearch server., (*9)

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

For example, for Elasticsearch 7.16, use 7.16 of this library or above, but not 8.0., (*11)

Compatibility

The Elasticsearch client is compatible with currently maintained PHP versions., (*12)

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., (*13)

Elasticsearch Version Elasticsearch-PHP Branch Supported
main main
8.x 8.x 8.x
7.x 7.x 7.17

Backward Incompatible Changes :boom:

The 8.0.0 version of elasticsearch-php contains a new implementation compared with 7.x. It supports PSR-7 for HTTP messages and PSR-18 for HTTP client communications., (*14)

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

  • we changed the namespace, now everything is under Elastic\Elasticsearch
  • we used the 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 response class. This class wraps a a 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! :angel:
  • 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 file for more information., (*16)

Mock the Elasticsearch client

If you need to mock the Elasticsearch client you just need to mock a PSR-18 HTTP Client., (*17)

For instance, you can use the php-http/mock-client as follows:, (*18)

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 project. If you are using PHPUnit you can even mock the ResponseInterface as follows:, (*19)

$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+., (*20)

For more information you can read the Mock client section of PHP-HTTP documentation., (*21)

FAQ 🔮

Where do I report issues with the client?

If something is not working as expected, please open an issue., (*22)

Where else can I go to get help?

You can checkout the Elastic community discuss forums., (*23)

Contribute 🚀

We welcome contributors to the project. Before you begin, some useful info..., (*24)

  • If you want to contribute to this project you need to subscribe to a Contributor Agreement.
  • Before opening a pull request, please create an issue to discuss the scope of your proposal.
  • 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. If you are not familiar with PHPUnit you can have a look at the reference.

Thanks in advance for your contribution! :heart:, (*25)

License 📗

MIT © Elastic, (*26)

The Versions

16/05 2018

5.0.x-dev

5.0.9999999.9999999-dev

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

11/04 2018
04/04 2018

2.0.x-dev

2.0.9999999.9999999-dev

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

22/12 2017

dev-loekvangool-patch-2

dev-loekvangool-patch-2

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

05/12 2017

v2.3.2

2.3.2.0

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

08/11 2017
25/08 2017

v2.3.1

2.3.1.0

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

24/08 2017
22/08 2017

v6.0.0-beta1

6.0.0.0-beta1

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

19/07 2017
12/06 2017

dev-loekvangool-patch-1

dev-loekvangool-patch-1

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

12/04 2017
21/02 2017

dev-sarwarbhuiyan-patch-2-1

dev-sarwarbhuiyan-patch-2-1

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

21/02 2017

dev-sarwarbhuiyan-patch-2

dev-sarwarbhuiyan-patch-2

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

21/02 2017

dev-sarwarbhuiyan-patch-1

dev-sarwarbhuiyan-patch-1

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

06/02 2017
03/02 2017

v5.1.2

5.1.2.0

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

02/02 2017

v5.1.1

5.1.1.0

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

06/01 2017

v5.1.0

5.1.0.0

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

30/11 2016

v2.3.0

2.3.0.0

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

04/11 2016

v2.2.3

2.2.3.0

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

26/10 2016
17/10 2016

v2.2.2

2.2.2.0

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

14/07 2016

v2.2.1

2.2.1.0

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

03/06 2016

v2.2.0

2.2.0.0

PHP Client for Elasticsearch

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

search elasticsearch client

15/04 2016
18/03 2016
08/01 2016
15/12 2015
01/12 2015
01/12 2015
01/12 2015
25/11 2015

1.0.x-dev

1.0.9999999.9999999-dev

PHP Client for Elasticsearch

  Sources   Download

Apache 2

The Requires

 

The Development Requires

search elasticsearch client

05/11 2015
23/09 2015
18/09 2015
28/08 2015
06/08 2015

v2.0.0-beta5

2.0.0.0-beta5

PHP Client for Elasticsearch

  Sources   Download

Apache 2

The Requires

 

The Development Requires

search elasticsearch client

22/05 2015

v2.0.0-beta4

2.0.0.0-beta4

PHP Client for Elasticsearch

  Sources   Download

Apache 2

The Requires

 

The Development Requires

search elasticsearch client

04/05 2015

v2.0.0-beta3

2.0.0.0-beta3

PHP Client for Elasticsearch

  Sources   Download

Apache 2

The Requires

 

The Development Requires

search elasticsearch client

09/04 2015

v2.0.0-beta2

2.0.0.0-beta2

PHP Client for Elasticsearch

  Sources   Download

Apache 2

The Requires

 

The Development Requires

search elasticsearch client

23/02 2015

v2.0.0-beta1

2.0.0.0-beta1

PHP Client for Elasticsearch

  Sources   Download

Apache 2

The Requires

 

The Development Requires

search elasticsearch client

14/02 2014

v1.0.1

1.0.1.0

PHP Client for Elasticsearch

  Sources   Download

Apache 2

The Requires

 

The Development Requires

search elasticsearch client

12/02 2014

v1.0

1.0.0.0

PHP Client for Elasticsearch

  Sources   Download

Apache 2

The Requires

 

The Development Requires

search elasticsearch client

07/01 2014

v0.4.4

0.4.4.0

PHP Client for Elasticsearch

  Sources   Download

Apache 2

The Requires

 

The Development Requires

search elasticsearch client

02/12 2013

v0.4.3

0.4.3.0

PHP Client for Elasticsearch

  Sources   Download

Apache 2

The Requires

 

The Development Requires

search elasticsearch client

13/11 2013