elasticsearch/elasticsearch
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
elastic/transport | v8.8.0 | - | MIT | prod | |
guzzlehttp/guzzle | 7.8.1 | 112.34 kB | MIT | prod | |
psr/http-client | 1.0.3 | - | MIT | prod dev | |
psr/log | 3.0.0 | 6.77 kB | MIT | prod dev |
The Elasticsearch PHP client, also known as "elasticsearch/elasticsearch," is the official PHP client for Elasticsearch. It offers over 400 endpoints to interact with Elasticsearch, facilitating operations such as indexing, searching, updating, and deleting documents. The client is designed to have compatibility with the Elasticsearch server and is versioned and released alongside it. Notably, the 8.0.0 version supports PSR-7 for HTTP messages and PSR-18 for HTTP client communications, reflecting a new approach compared to the 7.x version.
To utilize the elasticsearch/elasticsearch PHP client, it first needs to be installed in your project. This can typically be done via composer. Upon completion of installation, you can connect to Elasticsearch by referencing the Getting Started documentation's Connecting section. Subsequent usage to index, search, or delete content involves calling relevant API endpoints. For instance, to mock the Elasticsearch client, you may use the PHP-HTTP mock client and implement it as displayed in the README's provided code sample. Attention should be paid to ensure version compatibility between your Elasticsearch server and the PHP client for assured interoperability.
Here is a sample of code to establish an Elasticsearch client and mock an HTTP response:
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!
The comprehensive documentation for the Elasticsearch PHP client is available on the Elastic website. Specifically, the documents cover topics such as the installation, connecting to Elasticsearch, usage examples for various tasks, versioning, and information about backward incompatible changes. Information about endpoints for interacting with Elasticsearch is also available in the official Elasticsearch APIs documentation. In case you need to report issues with the client or seek help, the Elastic community discuss forums can be quite helpful.