ruflin/elastica), which is PHP-native and compatible with Laravel. However, Laravel’s service container (IoC) differs from Symfony’s, necessitating:
Elastica\Client and bundle services.fos_elastica YAML/XML) via Laravel’s config system.postPersist, postUpdate) must be translated to Eloquent observers or model events, adding complexity.Container, EventDispatcher, and Config components introduces architectural debt if not abstracted. Risks include:
ParameterBag, EventSubscriberInterface).FOS\ElasticaBundle\Finder\Paginator) in Laravel’s PHPUnit/Pest tests would require stubs or a dual-testing strategy.Why Elasticsearch?
Symfony Bridge Feasibility
Data Flow
elastica-bundle listeners)?Alternatives
Long-Term Support
ruflin/elastica).HttpKernel, EventDispatcher, and Config to Laravel’s container. Options:
AppServiceProvider (higher maintenance).FOS\ElasticaBundle\Serializer\SerializerPool and Laravel’s Arrayable/Jsonable.nelmio/cufon + jms/serializer-bundle (Symfony dependency) and bridge via the Symfony bridge.ruflin/elastica and test basic queries (e.g., Client->search()) in a Laravel controller.fos_elastica.yaml (or equivalent) in Laravel’s config/elastica.php.Indexer).// Example: Sync Eloquent 'saved' event to Elasticsearch
YourModel::saved(function ($model) {
app(\FOS\ElasticaBundle\Indexer::class)->index($model);
});
class ElasticsearchRepository {
public function __construct(private \FOS\ElasticaBundle\Finder\Paginator $paginator) {}
public function search(string $query) { ... }
}
| Feature | Compatibility | Workaround |
|---|---|---|
| Doctrine Listeners | ❌ Not natively supported | Eloquent observers or custom events |
| Symfony Config | ❌ YAML/XML not native | Convert to Laravel config (e.g., elastica.php) |
| EventDispatcher | ⚠️ Partial (requires bridge) | Manual event binding or custom dispatcher |
| JMS/Symfony Serializer | ❌ Not native | Adapter layer or use Laravel Serializer |
| Paginator | ⚠️ FOS\ElasticaBundle\Finder\Paginator needs binding |
Bind to Laravel’s container |
| Dynamic Mapping | ✅ Supported | Use Elastica\Document without schema |
.env:
ELASTICSEARCH_HOST=http://localhost:9200
ruflin/elastica, friendsofsymfony/elastica-bundle, and Symfony bridge (if used).config/elastica.php (mirroring fos_elastica.yaml):
return [
'clients' => [
'default' => [
'host' => env('ELASTICSEARCH_HOST'),
'port' => env('ELASTICSEARCH_PORT', 9200),
],
],
'indexes' => [
'app_product' => [
'settings' => ['number_of_shards' => 3],
'types' => [
'product' => ['properties' => [...]],
],
],
],
];
Elastica\Annotation\Document or Elastica\Document traits to models.How can I help you explore Laravel packages today?