Download the PHP package covertnija/elasticsearch-integration without Composer
On this page you can find all versions of the php package covertnija/elasticsearch-integration. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download covertnija/elasticsearch-integration
More information about covertnija/elasticsearch-integration
Files in covertnija/elasticsearch-integration
Package elasticsearch-integration
Short Description Symfony bundle for Elasticsearch integration with round-robin load balancing
License MIT
Informations about the package elasticsearch-integration
Elasticsearch Integration
A Symfony bundle providing an Elasticsearch client with round-robin load balancing, automatic failover, and Kibana-compatible logging.
Features
- Round-robin load balancing across multiple Elasticsearch nodes with automatic failover
- Symfony Bundle integration with full DI container support and autowiring
- Flexible configuration via YAML, environment variables, or programmatic setup
- Kibana-compatible logging via a Monolog formatter that maps
datetimeto@timestamp - Built-in Monolog handler with lazy initialization and enable/disable support
- Safe cache:clear — lazy-loaded HTTP client prevents connections during container compilation
- Host normalization — handles nested arrays from
%env(csv:...)%automatically - 100% test coverage with unit and integration tests
- PHPStan level 9 strict static analysis
- PSR-12 compliant with strict typing (
declare(strict_types=1))
Requirements
- PHP 8.2+
- Symfony 6.4+ or 7.x
- Elasticsearch 8.x+
elasticsearch/elasticsearch^9.2
Installation
Step 1: Install the package
Step 2: Register the bundle
With Symfony Flex — done automatically. Flex will:
- Register the bundle in
config/bundles.php - Create
config/packages/elasticsearch_integration.yaml - Add environment variables to
.env
Without Symfony Flex — add the bundle manually to config/bundles.php:
Step 3: Configure environment variables
Add the following to your .env file (Flex does this automatically):
For multiple hosts, use a comma-separated list:
Step 4: Create the configuration file
If Flex didn't create it, add config/packages/elasticsearch_integration.yaml:
Configuration Reference
Usage
Autowiring the Elasticsearch Client
The client is available via autowiring — just type-hint Client:
Using the Factory for Custom Clients
Inject the factory to create clients with different configurations:
Monolog / Kibana Integration
The bundle registers a LazyElasticsearchHandler that sends logs to Elasticsearch with Kibana-compatible @timestamp fields. The handler:
- Defers initialization — the inner
ElasticsearchHandleris only created when the first log is written, avoiding connection issues duringcache:clear - Respects the
enabledflag — silently discards logs when Elasticsearch is disabled - Auto-excludes the
elasticsearchchannel — prevents circular logging where the handler's own ES requests generate logs that feed back into itself - Applies KibanaCompatibleFormatter automatically
To use it, reference the bundle's handler service in your monolog config:
If you need a custom service name (e.g. for existing configs), create an alias:
The KibanaCompatibleFormatter renames Monolog's datetime field to @timestamp, which Kibana requires for time-based visualizations.
Architecture
Components
| Component | Description |
|---|---|
RoundRobinHttpClient |
PSR-18 HTTP client that distributes requests across hosts with automatic failover |
ElasticsearchRoundRobinClientFactory |
Factory that builds Client instances with validated options |
ElasticsearchConfig |
Immutable DTO for typed configuration with host normalization |
ElasticsearchExtension |
Symfony DI extension — registers all services programmatically |
KibanaCompatibleFormatter |
Monolog formatter mapping datetime → @timestamp |
LazyElasticsearchHandler |
Monolog handler with deferred initialization and enable/disable support |
How Round-Robin Load Balancing Works
- The
RoundRobinHttpClientrotates through configured hosts on each request - If a host fails (
ClientExceptionInterface), the next host is tried automatically - All hosts are attempted before throwing the first exception
- The round-robin index persists across requests for even distribution
- All operations are logged via the
elasticsearchMonolog channel
Available Services
| Service ID | Class | Description |
|---|---|---|
elasticsearch_integration.client |
Elastic\Elasticsearch\Client |
Main ES client |
elasticsearch_integration.client_factory |
ElasticsearchRoundRobinClientFactory |
Client factory |
elasticsearch_integration.round_robin_http_client |
RoundRobinHttpClient |
Lazy HTTP client with round-robin failover |
elasticsearch_integration.kibana_formatter |
KibanaCompatibleFormatter |
Monolog formatter |
elasticsearch_integration.monolog_handler |
LazyElasticsearchHandler |
Monolog handler for ES logging |
All services are private and available via autowiring:
Container Parameters
| Parameter | Type | Description |
|---|---|---|
elasticsearch_integration.enabled |
bool |
Whether the integration is active |
elasticsearch_integration.hosts |
array<string> |
Configured host URLs |
elasticsearch_integration.index |
string |
Default index name |
elasticsearch_integration.client_options |
array |
Client builder options |
elasticsearch_integration.ssl_verification |
bool |
Whether SSL certificate verification is enabled |
Security note: The API key is not exposed as a container parameter. It is passed directly to the client factory at build time.
Testing
Security
- API key not leaked — the API key is never stored as a container parameter
- API key authentication — use API keys instead of basic auth when possible
- SSL/TLS — always use HTTPS in production (
sslVerification: true) - Self-signed certificates — if your Elasticsearch cluster uses self-signed certificates, set
sslVerification: falseinclient_options. This disables both peer and host verification for the HTTP transport. Use only in trusted networks. - Network security — restrict access to Elasticsearch via firewall rules
- Input validation — sanitize all user input before sending to Elasticsearch
Contributing
- Fork the repository
- Create a feature branch
- Make your changes with tests (aim for 100% coverage)
- Run
composer checkto verify tests, PHPStan, and code style - Submit a pull request
License
MIT — see LICENSE for details.
All versions of elasticsearch-integration with dependencies
elasticsearch/elasticsearch Version ^9.2
monolog/monolog Version ^3.0
psr/log Version ^3.0
symfony/config Version ^6.4 || ^7.0
symfony/dependency-injection Version ^6.4 || ^7.0
symfony/http-client Version ^6.4 || ^7.0
symfony/http-kernel Version ^6.4 || ^7.0