Weave Code
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

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.

View on GitHub
Deep Wiki
Context7

An Elasticsearch implementation of Laravel's Eloquent ORM

Frequently asked questions about Elasticsearch
How do I install and configure pdphilip/elasticsearch in Laravel?
Install via Composer with `composer require pdphilip/elasticsearch`, then configure your Elasticsearch connection in `.env` under `ELASTICSEARCH_HOSTS` and update `config/database.php`. The package auto-detects Laravel 11–13, requiring no additional setup for most use cases.
Can I use Eloquent relationships (e.g., `with()`) with Elasticsearch queries?
Yes, the package supports hybrid queries like `UserLog::with('user')->whereMatch('bio', 'PHP')->get()`, but note that nested relationships may require careful mapping design to avoid performance issues or unsupported operations.
Does pdphilip/elasticsearch support fuzzy search or autocomplete?
Absolutely. Use `whereFuzzy()` for typo-tolerant searches or `searchPhrasePrefix()` for autocomplete-like queries. These methods leverage Elasticsearch’s built-in analyzers and are fully integrated into the Eloquent query builder.
What Laravel versions does this package support, and how do I upgrade?
The package supports Laravel 11–13. Upgrades are handled via Composer’s version constraints (e.g., `~5.6`), and the maintainer actively updates for new Laravel releases. Always test upgrades in a staging environment due to potential Elasticsearch API changes.
How do I handle geo-distance queries (e.g., finding users within 10km of a location)?
Use `whereGeoDistance('location', '10km', [lat, lng])` on your model. Ensure your Elasticsearch mapping includes a `geo_point` field for the location, and the package will handle the rest with native Elasticsearch geo-queries.
Can I paginate Elasticsearch results like Eloquent’s `paginate()`?
Yes, use `paginate(20)` or `simplePaginate()` just like Eloquent. The package abstracts Elasticsearch’s `from`/`size` parameters, but monitor performance for large datasets—consider adjusting `default_limit` in the config if needed.
What happens if Elasticsearch is down? Does the package support fallback to SQL?
The package does not natively support SQL fallbacks. If Elasticsearch fails, queries will throw exceptions. For hybrid reads, implement custom retry logic or use a circuit breaker pattern to gracefully degrade functionality.
How do I initialize or re-index an Elasticsearch index for my models?
Use the `elastic:re-index` Artisan command to sync your database records with Elasticsearch. For large datasets, consider batch processing or async queues to avoid throttling. The package also provides `elastic:make` for scaffolding new models.
Are there performance considerations for high-write scenarios (e.g., bulk inserts)?
For high-frequency writes, use `bulkInsert()` to reduce round-trips to Elasticsearch. Monitor cluster health and consider async indexing via Laravel queues. The package supports bulk operations but may require tuning `ES_HOSTS` for resilience.
What alternatives exist for Elasticsearch in Laravel, and why choose this package?
Alternatives include `scientia/elasticsearch-laravel` or `ruflin/elastica`, but this package uniquely extends Eloquent’s query builder, reducing the learning curve. It’s ideal if you need seamless integration with Laravel’s conventions, built-in search helpers (e.g., `highlight()`), and geo queries.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests