pdphilip/elasticsearch
Laravel Eloquent-style ORM for Elasticsearch. Use familiar models and query builder methods to create, update, paginate, delete, and run ES searches: term/phrase, match, fuzzy, geo distance, highlighting, and more—designed to feel native in Laravel.
Model::searchTerm(), whereMatch(), whereGeoDistance()). This reduces cognitive load and accelerates adoption.UserLog::with('user')), making it ideal for applications requiring full-text search, analytics, or geospatial queries alongside traditional SQL operations..env + config/database.php), and the package auto-detects Laravel versions (11–13) with zero manual setup for most use cases.elastic:re-index and elastic:make automate migration, scaffolding, and re-indexing, reducing manual effort for schema updates or model creation.default_limit config helps mitigate this but requires monitoring.whereNestedObject()) add complexity and may require careful mapping design to avoid performance pitfalls.Use Case Alignment:
Data Volume and Velocity:
bulkInsert()) or async queues to avoid throttling Elasticsearch.ES_HOSTS configuration.Operational Readiness:
Migration Path:
JOINs, complex subqueries) that may require redesign.elastic:re-index, but large datasets may need custom scripts or batch processing.Long-Term Maintenance:
~5.6 for L11–13) suggests frequent updates; ensure CI/CD pipelines can handle dependency updates.elasticlens for SQL-to-ES sync) may influence adoption.Assessment Phase:
LIKE queries, complex JOINs).Pilot Implementation:
UserProfile) and its most critical queries (e.g., search, geolocation).elastic:make to scaffold the model and mappingDefinition() to define fields. Example:
public static function mappingDefinition(Blueprint $index): void {
$index->text('bio')->analyzer('english');
$index->geoPoint('location');
$index->keyword('country_code')->index(true);
}
elastic:re-index or a custom script.Hybrid Phase:
DB::select("SELECT * FROM users WHERE name LIKE '%John%'") with:
User::searchTerm('John')->get();
Full Transition:
spatie/laravel-activitylog (if using Elasticsearch for event storage) or laravel-notification-channels/elasticsearch.Infrastructure Setup:
.env and config/database.php with connection details.php artisan tinker:
\PDPhilip\Elasticsearch\Connection::connection()->ping();
Model Layer:
elastic:make and define mappings.mappingDefinition() for each model, starting with high-priority fields.Query Layer:
whereMatch(), whereGeoDistance()).Data Layer:
elastic:re-index or bulk APIs.Observability:
ES_OPT_LOGGING).Schema Management:
mappingDefinition() in models for version-controlled schema changes.elastic:re-index for zero-downtime migrations (e.g., adding/removing fields, changing analyzers).mappingDefinition().php artisan elastic:re-index User --force.php artisan elastic:verify User.Dependency Updates:
Connection::select() signature).composer test:all to validate compatibility.Backup Strategy:
curl or the Elasticsearch API.Debugging:
ES_OPT_LOGGING=true) to inspect DSL generated by the package.Grammar::compileMapping() to debug mapping definitions before applying them.$query = User::searchTerm('test')->toElasticsearchQuery();
dd($query->toArray());
Common Pitfalls:
How can I help you explore Laravel packages today?