zvonchuk / elasticsearch-php-client
PHP High Level REST Client
Package info
github.com/zvonchuk/elasticsearch-php-client
pkg:composer/zvonchuk/elasticsearch-php-client
v1.0.0
2026-09-28 20:57 UTC
Requires
- php: ^8.1
- elasticsearch/elasticsearch: ^7.11
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-09-30 09:05:19 UTC
README
High-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.
Features
- Fluent, typed query building in the style of the Java High Level REST Client
bool,match,multi_match,term,terms,range,exists,prefix,wildcard,ids,fuzzy,dis_max,constant_score,nested, geo queries —boost()andqueryName()on every query- Typed responses:
SearchHitobjects with matched queries, mapping hits to your own classes - Multi search: several searches in one round trip, failures reported instead of passing for empty results
- Aggregations with sub-aggregations, sorting, document and bulk operations
- Index management with aliases and atomic alias swaps for reindexing without downtime
- Wraps an official
elasticsearch/elasticsearchclient you configure — no hidden connections
Documentation
- Getting Started
- Client Setup
- Searching and Responses
- Queries
- Aggregations
- Document Operations
- Indices Management
- Sorting
- Advanced Examples
- Changelog · Upgrading from 0.x
Installation via Composer
composer require zvonchuk/elasticsearch-php-client
Requirements
| elasticsearch-php-client | PHP | Elasticsearch | Official client |
|---|---|---|---|
| 1.x | >= 8.1 | 7.x | elasticsearch/elasticsearch ^7.11 |
| 0.x | >= 7.4 | 7.x | elasticsearch/elasticsearch ^7.11 |
Quick Start Example
<?php require 'vendor/autoload.php'; use Zvonchuk\Elastic\Client; use Zvonchuk\Elastic\Core\SearchRequest; use Zvonchuk\Elastic\Query\QueryBuilders; use Zvonchuk\Elastic\Search\Builder\SearchSourceBuilder; // Connect (or wrap an official client you configured: new Client($elasticsearch)) $client = Client::create(['localhost:9200']); // Build the search $query = QueryBuilders::boolQuery() ->must(QueryBuilders::matchQuery('title', 'elasticsearch')->operator('and')->queryName('title')) ->filter(QueryBuilders::termQuery('published', true)); $source = (new SearchSourceBuilder())->query($query)->size(20)->timeout('2s'); $response = $client->search((new SearchRequest('articles'))->source($source)); // Process results foreach ($response->hits() as $hit) { echo "{$hit->id} ({$hit->score}): {$hit->source['title']}\n"; }
Development
composer test # unit tests ELASTICSEARCH_URL=http://localhost:9200 composer test:integration composer analyse # PHPStan level 8