ongr/elasticsearch-dsl
Object-oriented Elasticsearch query builder for PHP. Build searches, filters, aggregations and more with a DSL, then export to arrays for elasticsearch-php or ONGR ElasticsearchBundle. Supports Elasticsearch 5/6/7 via versioned releases.
Strengths:
elasticsearch-php: Leverages the official Elasticsearch PHP client, ensuring compatibility and reliability.Fit for Laravel:
elasticsearch/elasticsearch v6).Weaknesses:
Laravel Stack Compatibility:
composer require ongr/elasticsearch-dsl.Key Integration Points:
/api/products/search).Data Flow:
ModelObserver or ModelEvents to push data to Elasticsearch (e.g., saved, deleted).High:
Elasticsearch\Common\Exceptions\ElasticsearchException).Medium:
elasticsearch-php’s mock client or tools like elasticsearch-dsl-test).Low:
Elasticsearch Strategy:
Data Synchronization:
Performance Requirements:
Operational Ownership:
Fallback Strategy:
Long-Term Maintenance:
Laravel Ecosystem:
// app/Providers/ElasticsearchServiceProvider.php
public function register()
{
$this->app->singleton(Client::class, function ($app) {
return ClientBuilder::create()->build();
});
$this->app->singleton(Search::class, function ($app) {
return new Search();
});
}
Elasticsearch::search()).ProductSearchRepository).Database Synergy:
// app/Observers/ProductObserver.php
public function saved(Product $product)
{
$search = new Search();
$search->addDocument($product->toArray());
Elasticsearch::index('products', $product->id, $search->toArray());
}
ElasticsearchMigrator class).API Layer:
// app/Http/Controllers/SearchController.php
public function search(Request $request)
{
$query = new MatchQuery('title', $request->query('q'));
$search = new Search();
$search->addQuery($query);
$results = Elasticsearch::search('products', $search->toArray());
return response()->json($results);
}
FormRequest.Testing:
elasticsearch-php’s mock client or tools like mocks\elasticsearch for unit tests.Assessment Phase:
Pilot Integration:
Incremental Rollout:
match, term, bool).Deprecation:
Elasticsearch Client:
elasticsearch/elasticsearch v7+. Ensure the Laravel app’s Elasticsearch cluster version is compatible (see version matrix).Laravel Versions:
Database Schema:
Product model:
$params = [
'index' => 'products',
'body' => [
'mappings' => [
How can I help you explore Laravel packages today?