Getting Started
Install ElasticLens and connect your first model to Elasticsearch in under a minute.
Installation
Section titled “Installation”- Laravel 10/11/12
- Elasticsearch 8.x
Before you start, you’ll need to configure your Elasticsearch connection for Laravel. See the Laravel-Elasticsearch Getting Started Guide for full setup instructions.
composer require pdphilip/elasticlensPublish the config file and run the migrations with:
php artisan lens:installRun the migrations to create the index build and migration logs indexes:
php artisan migrateOptional Configuration
Section titled “Optional Configuration”lens:install will publish the config file to config/elasticlens.php and create the migration files build and migration logs.
You can customize the configuration in config/elasticlens.php
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 acts as a separate Elasticsearch model managed by ElasticLens, yet you retain full control over it, just like any other Laravel model. In addition to working directly with the Index Model, ElasticLens offers tools for
- Full-text searching of your Base Models using the full feature set of the Larevel-Elasticsearch package
- Mapping fields (with embedded relationships) during the build process
- Define Index Model migrations.
- Conditional indexing to exclude specific records
- Soft delete support to keep or remove index records on soft delete
- CLI tools to view sync status and manage your Index Models
For Example, a base User Model will sync with an Elasticsearch IndexedUser Model that provides all the features from Laravel-Elasticsearch to search your base User Models