kinetis / search-elasticsearch
Fiber-native non-blocking Elasticsearch client construction for Kinetis, on kinetis/search's Revolt-backed HTTP transport.
Requires
- php: ^8.4
- elastic/transport: ^8.11 || ^9.0
- elasticsearch/elasticsearch: ^8.19 || ^9.0
- kinetis/framework: ^1.5.2
- kinetis/search: ^1.0.0
- psr/container: ^2.0.2
- psr/http-client: ^1.0.3
Requires (Dev)
- infection/infection: ^0.35.0
- kinetis/revolt-http-client: ^1.3.1
- phpstan/phpstan: ^2.2.8
- phpunit/phpunit: ^12.5.33
- vimeo/psalm: ^6.16.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
kinetis/search-elasticsearch
Non-blocking Elasticsearch client construction for Kinetis
Part of Kinetis, a non-blocking PHP framework for API-first applications, developed in the kinetis-dev/kinetis monorepo.
Builds a real Elastic\Elasticsearch\Client (from
elasticsearch/elasticsearch) through Elasticsearch's own ClientBuilder,
over kinetis/search's
Revolt-native HTTP transport instead of the blocking cURL client the
builder would otherwise discover. The returned object is the real,
un-wrapped client — nothing Kinetis-specific sits on top of it.
Each call is one wire attempt against one origin, bounded by one deadline
and one response size, following no redirect and making no retry:
Elastic\Transport\Transport re-sends on a PSR-18 network failure, which
would replay an index or bulk whose dispatch outcome is unknown, so
retries are pinned to zero. Every status Elasticsearch answers with stays
the official client's to map.
use Kinetis\SearchElasticsearch\ElasticsearchClientFactory; $client = ElasticsearchClientFactory::fromConfig($config); $client->index(['index' => 'articles', 'id' => '1', 'body' => ['title' => 'Kinetis']]); $results = $client->search(['index' => 'articles', 'body' => ['query' => ['match' => ['title' => 'Kinetis']]]]);
Provides
Installing this package auto-registers, via extra.kinetis:
- A container binding for
Elastic\Elasticsearch\ClientwhenSEARCH_ELASTICSEARCH_HOSTis set, and one forkinetis/search's engine-neutralSearchClientover it. Unset means the package binds nothing. Neither is shared:Elastic\Transport\Transportkeeps the last request and response it saw, so one client per worker would hold one request's documents until the next search displaced them. The transport that owns the connection pool is built once during registration — opening no connection, so unusable configuration fails at boot rather than on the first search — and each resolution gets its own client over it. An application's ownbootstrap.phpruns afterwards and can replace either binding.
Nothing else. Named connections stay explicit application wiring.
Configuration
SEARCH_ELASTICSEARCH_HOST=https://localhost:9200
The host, deadline, response bound, Basic credentials and TLS switch are
kinetis/search's, spelled with
this engine's prefix. What this package adds:
| Key | Default | Purpose |
|---|---|---|
SEARCH_ELASTICSEARCH_API_KEY |
— | An API key — the encoded value the cluster hands out, or the secret alongside the id below. Travels as an Authorization: ApiKey header, never in the URL. |
SEARCH_ELASTICSEARCH_API_KEY_ID |
— | The key's id, when it is held separately from its secret. |
An API key and SEARCH_ELASTICSEARCH_USERNAME together are refused while
the client is built: they are two credentials for one request.
Every key is scoped — SEARCH_ELASTICSEARCH_HOST + logs →
SEARCH_LOGS_ELASTICSEARCH_HOST. Full reference:
kinetis.dev/docs/search.html.
Matching the client to your cluster
elasticsearch/elasticsearch ^8.19 || ^9.0 is accepted, and the major
must match the cluster's: a 9.x client sends compatible-with=9, which
an 8.x cluster rejects. Composer resolves to the newest allowed release,
so an Elasticsearch 8 cluster needs the constraint pinned in your own
application:
composer require elasticsearch/elasticsearch:^8.19
Installation
composer require kinetis/search-elasticsearch
Requires PHP 8.4+, kinetis/framework,
and kinetis/search.
Full documentation:
kinetis.dev/docs/search-elasticsearch.html.
License
MIT — see LICENSE.