Getting Started
Trait on. Index built. Searching in under a minute.
Installation
Section titled “Installation”- Laravel 10/11/12
- Elasticsearch 8.x
You’ll need your Elasticsearch connection configured first. See the Laravel-Elasticsearch Getting Started Guide if you haven’t done that yet.
composer require pdphilip/elasticlensPublish the config file and create migration files:
php artisan lens:installRun the migrations:
php artisan migrateOptional Configuration
Section titled “Optional Configuration”lens:install publishes config/elasticlens.php and creates migrations for the build state and migration log indexes.
return [ 'database' => 'elasticsearch',
'queue' => null, // Set queue to use for dispatching index builds
'index_soft_deletes' => false, // See: Soft Delete Support
'watchers' => [ // \App\Models\Profile::class => [ // \App\Models\Indexes\IndexedUser::class, // ], ],
'index_build_state' => [ 'enabled' => true, 'log_trim' => 2, ],
'index_migration_logs' => [ 'enabled' => true, ], 'namespaces' => [ 'App\Models' => 'App\Models\Indexes', ],
'index_paths' => [ 'app/Models/Indexes/' => 'App\Models\Indexes', ],];How It Works
Section titled “How It Works”The Index Model is a separate Elasticsearch model that ElasticLens manages for you. It’s still a real model you can query and inspect directly, just like any other Eloquent model.
On top of that, ElasticLens gives you:
- Full-text search on your Base Models using the entire Laravel-Elasticsearch query builder
- Field mapping with embedded relationships during builds
- Index Model migrations for schema control
- Conditional indexing to skip specific records
- Soft delete support to keep or remove index records on soft delete
- CLI tools for status, health, builds, and migrations
So a User model syncs with an IndexedUser model in Elasticsearch. Every search feature from Laravel-Elasticsearch is now available on your User models.