OpenSearch index migrations for Laravel.
Install the package with Composer:
composer require directorytree/opensearch-migrationsPublish the OpenSearch client configuration:
php artisan vendor:publish --provider="DirectoryTree\OpenSearchClient\OpenSearchClientServiceProvider"Publish the migration configuration:
php artisan vendor:publish --provider="DirectoryTree\OpenSearchMigrations\OpenSearchMigrationsServiceProvider"Run Laravel migrations to create the OpenSearch migrations table:
php artisan migrateThe migration configuration is published to config/opensearch.migrations.php:
'table' => env('OPENSEARCH_MIGRATIONS_TABLE', 'opensearch_migrations'),
'connection' => env('OPENSEARCH_MIGRATIONS_CONNECTION'),
'storage_directory' => env('OPENSEARCH_MIGRATIONS_DIRECTORY', base_path('opensearch/migrations')),
'index_name_prefix' => env('OPENSEARCH_MIGRATIONS_INDEX_NAME_PREFIX', env('SCOUT_PREFIX', '')),
'alias_name_prefix' => env('OPENSEARCH_MIGRATIONS_ALIAS_NAME_PREFIX', env('SCOUT_PREFIX', '')),Create a migration:
php artisan opensearch:make:migration create_posts_indexMigration files are stored in opensearch/migrations by default:
use DirectoryTree\OpenSearchAdapter\Indices\Mapping;
use DirectoryTree\OpenSearchAdapter\Indices\Settings;
use DirectoryTree\OpenSearchMigrations\Facades\Index;
use DirectoryTree\OpenSearchMigrations\MigrationInterface;
class CreatePostsIndex implements MigrationInterface
{
public function up(): void
{
Index::create('posts', function (Mapping $mapping, Settings $settings) {
$mapping->text('title');
$mapping->text('body');
});
}
public function down(): void
{
Index::dropIfExists('posts');
}
}Run all pending migrations:
php artisan opensearch:migrateRun a single migration:
php artisan opensearch:migrate 2026_01_01_000000_create_posts_indexRoll back the last batch:
php artisan opensearch:migrate:rollbackRoll back every migrated file:
php artisan opensearch:migrate:resetRoll back and rerun every migration:
php artisan opensearch:migrate:refreshDrop all indexes and rerun every migration:
php artisan opensearch:migrate:freshShow migration status:
php artisan opensearch:migrate:status