Elasticsearch PHP Client

Official PHP client for indexing, searching, and managing Elasticsearch clusters

SDK
Composer
vv9.5.0
5,338stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
82/100Excellent
Development Activity72
Maintenance64
Community92
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture84
Code Quality86
Innovation72
Learning Curve68

The Elasticsearch PHP client is Elastic’s officially maintained library for talking to Elasticsearch from PHP applications. It exposes the full Elasticsearch REST API surface — search, indexing, cluster management, ingest pipelines, machine learning, and more — as strongly-typed PHP methods generated directly from Elasticsearch’s API specification, so the client stays in sync with server capabilities across versions.

Under the hood it is built on Elastic’s shared elastic/transport library and PSR interfaces (PSR-7, PSR-17, PSR-18), letting it plug into whichever HTTP client and message factory a PHP project already uses (Guzzle, Symfony HttpClient, etc.) rather than bundling its own. This makes it the standard choice for PHP applications and frameworks that need direct, low-level access to an Elasticsearch cluster rather than going through a higher-level search abstraction.

What You Get

  • Full coverage of the Elasticsearch REST API (search, indices, cluster, ingest, ML, security, and more) as generated PHP methods
  • A fluent ClientBuilder for configuring hosts, authentication (API key, basic auth, bearer token), SSL, and retry behavior
  • PSR-7/PSR-17/PSR-18 based transport, so it works with Guzzle, Symfony HttpClient, or any compliant PSR HTTP client already in the project
  • Typed response objects and structured exceptions for API errors, distinguishing client, server, and network failures
  • Async request support and configurable retry/backoff for resilient production usage

Common Use Cases

  • Building full-text search features (product search, log search, autocomplete) backed by an Elasticsearch cluster from a PHP backend
  • Indexing and bulk-updating documents from a Laravel, Symfony, or plain PHP application
  • Cluster administration and index-lifecycle scripting (creating/deleting indices, managing mappings and ILM policies) from PHP tooling
  • Integrating Elasticsearch aggregations and analytics queries into PHP-based dashboards or reporting tools

Under The Hood

Architecture Client.php and ClientInterface.php form the top-level entry point, delegating each REST call to a generated endpoint class under src/Endpoints/ (one class per API area — Cat.php, Cluster.php, Enrich.php, AsyncSearch.php, and dozens more) that extends AbstractEndpoint.php to build the request URI, method, and body from typed parameters. Requests are handed to the Transport/ layer, which is built on the separate elastic/transport package and PSR-18 HTTP client abstractions, so the actual socket/HTTP work is delegated to whatever PSR-compliant client (Guzzle, Symfony HttpClient) the consuming application supplies. Responses flow back through Response/ wrapper classes and Exception/ types that translate Elasticsearch error payloads into typed PHP exceptions. Tech Stack Requires PHP 8.1+, depends on elastic/transport for HTTP transport and psr/http-client, psr/http-message, and psr/log for its PSR interfaces; dev dependencies include PHPUnit 10, PHPStan level analysis, Mockery, and Guzzle/Symfony HttpClient/nyholm-psr7 for integration testing against multiple transport backends. Code Quality The tests/ directory is organized into Transport, Response, Traits, Helper, and Integration suites, plus separate PHPUnit configs for unit, integration, cloud, and YAML-spec-driven serverless tests (phpunit-yaml-serverless-tests.xml, phpunit-integration-cloud-tests.xml), indicating the client is validated against Elastic’s official API test specs in addition to hand-written unit tests; PHPStan is run as part of the standard composer scripts for static analysis. API Design The generated, namespaced method structure ($client->indices()->create(), $client->cat()->indices()) closely mirrors the underlying REST API paths, which keeps the client’s shape predictable for anyone who already knows the Elasticsearch HTTP API, at the cost of some verbosity and reliance on associative-array parameters for complex request bodies.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search