Index-model migrations
Define your index-model’s migrationMap()
to take control of the index structure.
Define the migrationMap()
Section titled “Define the migrationMap()”Elasticsearch automatically indexes new fields it encounters, but it may not always index them in the way you need. To ensure the index is structured correctly, you can define a migrationMap()
in your Index Model.
Since the Index Model utilizes the Laravel-Elasticsearch package, use Index Blueprint to define your index’s field map in the migrationMap()
method.
use PDPhilip\Elasticsearch\Schema\Blueprint;
class IndexedUser extends IndexModel{ //...... public function migrationMap(): callable { return function (Blueprint $index) { $index->text('name'); $index->keyword('first_name'); $index->text('first_name'); $index->keyword('last_name'); $index->text('last_name'); $index->keyword('email'); $index->text('email'); $index->text('avatar')->indexField(false); $index->keyword('type'); $index->text('type'); $index->keyword('state'); $index->text('state'); //...etc }; }
Run the Migration
Section titled “Run the Migration”php artisan lens:migrate User
This command will delete the existing index and records, run the migration, and rebuild all records.
