Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Elasticsearch

Elasticsearch Laravel Package

pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM. Use familiar Eloquent methods and models while leveraging full-text search, geo queries, fuzzy matching, highlights, and aggregations through a seamless Laravel-native integration.

View on GitHub
Deep Wiki
Context7

pdphilip/elasticsearch brings the power of Elasticsearch to Laravel through a native Eloquent ORM implementation. It extends the familiar Eloquent model and query builder, letting you create, update, paginate, and delete documents while unlocking advanced full-text search and analytics—no new API to learn.

  • Familiar Eloquent syntax (where, create, update, paginate, delete)
  • Full-text search: searchTerm, searchPhrasePrefix, whereMatch
  • Geo queries with whereGeoDistance and fuzzy matching
  • Highlighting and relevance-aware result retrieval
  • Seamless integration with existing Laravel models
Frequently asked questions about Elasticsearch
How do I integrate Elasticsearch into my Laravel app without breaking Eloquent?
The package extends Eloquent natively, so you can use familiar methods like `where()`, `searchTerm()`, or `geoDistance()` directly on models. Just configure your `.env` with Elasticsearch credentials, register the service provider, and run `php artisan elastic:make` to scaffold models. No need to rewrite queries—just add search-specific methods.
Does this package support Laravel 11+ and Elasticsearch 8.x?
Yes, it’s fully compatible with Laravel 11+ and Elasticsearch 8.x. Older versions (e.g., Laravel 10, ES 7.x) are supported via separate branches. The package auto-adapts to Laravel’s query builder changes (e.g., Laravel 13’s `Connection::select()`) to avoid breaking updates.
Can I mix SQL and Elasticsearch queries in the same app?
Absolutely. The package supports hybrid queries, including relationships like `UserLog::with('user')`. However, ensure data consistency by syncing writes (e.g., using Laravel events or queues) since Elasticsearch operates asynchronously by default.
How do I handle schema migrations for Elasticsearch indices?
Use the `elastic:re-index` Artisan command to automate schema migrations. Define mappings in Laravel migrations with the Blueprint DSL, then run the command to sync changes. For large datasets, test migrations in staging first—downtime may be required depending on your cluster setup.
What if my search queries return too many results? How do I optimize performance?
Set `ES_OPT_DEFAULT_LIMIT` in your `.env` to cap results (default: 1000). For large datasets, use pagination (`paginate()`) or Elasticsearch’s scroll API. Avoid broad queries without filters; leverage `whereMatch()` or `geoDistance()` to narrow results early in the query pipeline.
Does this package support geospatial queries like finding users within 10km of a location?
Yes, use `whereGeoDistance('location', '10km', [lat, lng])` on models with geo_point fields. Ensure your Elasticsearch mapping includes `geo_point` types for the relevant fields. For complex geospatial logic, consider pre-filtering with bounding boxes to improve performance.
How do I debug Elasticsearch queries or mappings?
Use `Schema::compileMapping()` to inspect generated mappings before applying them. For query debugging, enable Elasticsearch’s `pretty` response format in `.env` (e.g., `ES_OPT_PRETTY=true`) or log raw queries with `->toDebugString()`. The package also integrates with Laravel’s query logging.
What are the alternatives if I need more advanced Elasticsearch features (e.g., nested fields, aggregations)?
For nested fields or complex aggregations, you may need to use Elasticsearch’s raw DSL via the package’s `Elasticsearch::raw()` method. Alternatively, consider packages like `ruflin/elastica` for low-level control, though they lack Eloquent integration. This package balances convenience and power for 80% of use cases.
How do I handle fuzzy matching or typo-tolerant searches?
Use `whereFuzzy()` for typo-tolerant searches (e.g., `whereFuzzy('name', 'john')`). Configure analyzers in your mapping (e.g., `standard` or `english` analyzers) to control tokenization. For custom fuzzy logic, pass parameters like `fuzziness: 2` to the method.
Is this package suitable for production with high traffic?
Yes, but monitor Elasticsearch cluster health and query performance. Use managed services (e.g., Elastic Cloud) for scalability, and implement caching (e.g., Redis) for frequent queries. Test under load with tools like `k6` or `Artillery` to identify bottlenecks before deployment.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console