PHPackages                             panytsch/elastic-migrations-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. panytsch/elastic-migrations-laravel

ActiveLibrary[Search &amp; Filtering](/categories/search)

panytsch/elastic-migrations-laravel
===================================

Elasticsearch migrations for Laravel

v1.3.2(5y ago)010MITPHPPHP ^7.2

Since May 1Pushed 5y agoCompare

[ Source](https://github.com/panytsch/elastic-migrations-laravel)[ Packagist](https://packagist.org/packages/panytsch/elastic-migrations-laravel)[ RSS](/packages/panytsch-elastic-migrations-laravel/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (1)Dependencies (6)Versions (9)Used By (0)

Elastic Migrations
==================

[](#elastic-migrations)

[![Latest Stable Version](https://camo.githubusercontent.com/bbc5665c2dbb4ac1ca14df69f932c564af70de6c351ca4e53b49e7c775481ff5/68747470733a2f2f706f7365722e707567782e6f72672f626162656e6b6f6976616e2f656c61737469632d6d6967726174696f6e732f762f737461626c65)](https://packagist.org/packages/babenkoivan/elastic-migrations)[![Total Downloads](https://camo.githubusercontent.com/d4bdd5059ee37ff0fcbfefbf9e0ef164212ed28a75f637f94e641ca7dea5250a/68747470733a2f2f706f7365722e707567782e6f72672f626162656e6b6f6976616e2f656c61737469632d6d6967726174696f6e732f646f776e6c6f616473)](https://packagist.org/packages/babenkoivan/elastic-migrations)[![License](https://camo.githubusercontent.com/53a3fc344d478a37bc06195bb3f2377cc6633ba8280b246e9ae20c1130a90dfa/68747470733a2f2f706f7365722e707567782e6f72672f626162656e6b6f6976616e2f656c61737469632d6d6967726174696f6e732f6c6963656e7365)](https://packagist.org/packages/babenkoivan/elastic-migrations)[![Tests](https://github.com/babenkoivan/elastic-migrations/workflows/Tests/badge.svg)](https://github.com/babenkoivan/elastic-migrations/actions?query=workflow%3ATests)[![Code style](https://github.com/babenkoivan/elastic-migrations/workflows/Code%20style/badge.svg)](https://github.com/babenkoivan/elastic-migrations/actions?query=workflow%3A%22Code+style%22)[![Static analysis](https://github.com/babenkoivan/elastic-migrations/workflows/Static%20analysis/badge.svg)](https://github.com/babenkoivan/elastic-migrations/actions?query=workflow%3A%22Static+analysis%22)[![Donate PayPal](https://camo.githubusercontent.com/0b8a275d67dfb2aa74ac299fa07b7fce95217f6620448d88cf05ff9e3653e9bf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f6e6174652d70617970616c2d626c7565)](https://paypal.me/babenkoi)

---

Elasticsearch migrations for Laravel allow you to easily modify and share indices schema across the application's environments.

Contents
--------

[](#contents)

- [Compatibility](#compatibility)
- [Fork changes](#fork-changes)
- [Installation](#installation)
- [Configuration](#configuration)
- [Writing Migrations](#writing-migrations)
- [Running Migrations](#running-migrations)
- [Reverting Migrations](#reverting-migrations)
- [Starting Over](#starting-over)
- [Migration Status](#migration-status)
- [Troubleshooting](#migration-status)

Compatibility
-------------

[](#compatibility)

The current version of Elastic Migrations has been tested with the following configuration:

- PHP 7.2-7.4
- Elasticsearch 7.x
- Laravel 6.x-8.x

Fork changes
------------

[](#fork-changes)

This specific forked version doesn't need MySQL to save migrations results. You may use Elasticsearch only. To do this you just need: Set environment variables

```
SAVE_MIGRATIONS_TO_ELASTIC=true
MIGRATIONS_INDEX=name_of_index_to_store_migrations_result
```

OR

change this configs in file `elastic.migrations.php`

After this you have to create this elastic index (will be automated in future versions) with mapping:

```
{
    "mappings" : {
        "properties" : {
            "batch" : {
                "type" : "integer"
            },
            "migration" : {
                "type" : "keyword"
            }
        }
    }
}
```

Installation
------------

[](#installation)

The library can be installed via Composer:

```
composer require babenkoivan/elastic-migrations
```

If you want to use Elastic Migrations with [Lumen framework](https://lumen.laravel.com/) check [this guide](https://github.com/babenkoivan/elastic-migrations/wiki/Lumen-Installation).

Configuration
-------------

[](#configuration)

Elastic Migrations uses [babenkoivan/elastic-client](https://github.com/babenkoivan/elastic-client) as a dependency. If you want to change the default client settings (and I'm pretty sure you do), then you need to create the configuration file first:

```
php artisan vendor:publish --provider="ElasticClient\ServiceProvider"
```

You can change Elasticsearch host and other client settings in the `config/elastic.client.php` file. Please refer to [babenkoivan/elastic-client](https://github.com/babenkoivan/elastic-client) for more details.

If you want to change the migration **default table name**, the **migrations directory** or set an **index name prefix**, publish Elastic Migrations settings as well:

```
php artisan vendor:publish --provider="ElasticMigrations\ServiceProvider"
```

The published configuration can be found in the `config/elastic.migrations.php` file.

Finally, don't forget to run Laravel database migrations to create Elastic Migrations table:

```
php artisan migrate
```

Writing Migrations
------------------

[](#writing-migrations)

You can effortlessly create a new migration file using an Artisan console command:

```
php artisan elastic:make:migration create_my_index
```

This command creates a migration class in the `elastic/migrations` directory.

Every migration includes two methods: `up` and `down`. `up` is used to alternate the index schema and `down` is used to revert that action.

You can use `ElasticMigrations\Facades\Index` facade to perform basic operations over Elasticsearch indices:

#### Create Index

[](#create-index)

Create an index with the default settings:

```
Index::create('my-index');
```

or use a modifier to configure mapping and settings:

```
Index::create('my-index', function (Mapping $mapping, Settings $settings) {
    // to add a new field to the mapping use method name as a field type (in Camel Case),
    // first argument as a field name and optional second argument as additional field parameters
    $mapping->text('title', ['boost' => 2]);
    $mapping->float('price');

    // you can define a dynamic template as follows
    $mapping->dynamicTemplate('my_template_name', [
        'match_mapping_type' => 'long',
        'mapping' => [
            'type' => 'integer',
        ],
    ]);

    // you can also change the index settings
    $settings->index([
         'number_of_replicas' => 2,
         'refresh_interval' => -1
    ]);

    // and analisys configuration
    $settings->analysis([
        'analyzer' => [
            'title' => [
                'type' => 'custom',
                'tokenizer' => 'whitespace'
            ]
        ]
    ]);
});
```

There is also an option to create an index only if it doesn't exist:

```
Index::createIfNotExists('my-index');
```

#### Update Mapping

[](#update-mapping)

Use the modifier to adjust the mapping:

```
Index::putMapping('my-index', function (Mapping $mapping) {
    $mapping->text('title', ['boost' => 2]);
    $mapping->float('price');
});
```

#### Update Settings

[](#update-settings)

Use the modifier to change the index configuration:

```
Index::putSettings('my-index', function (Settings $settings) {
    $settings->index([
         'number_of_replicas' => 2,
         'refresh_interval' => -1
    ]);
});
```

You can update analysis settings only on closed indices. The `putSettingsHard` method closes the index, updates the configuration and opens the index again:

```
Index::putSettingsHard('my-index', function (Settings $settings) {
    $settings->analysis([
        'analyzer' => [
            'title' => [
                'type' => 'custom',
                'tokenizer' => 'whitespace'
            ]
        ]
    ]);
});
```

#### Drop Index

[](#drop-index)

You can unconditionally delete the index:

```
Index::drop('my-index');
```

or delete it only if it exists:

```
Index::dropIfExists('my-index');
```

#### More

[](#more)

Finally, you are free to inject `Elasticsearch\Client` in the migration constructor and execute any supported by client actions.

Running Migrations
------------------

[](#running-migrations)

You can either run all migrations:

```
php artisan elastic:migrate
```

or run a specific one:

```
php artisan elastic:migrate 2018_12_01_081000_create_my_index
```

Use the `--force` option if you want to execute migrations on production environment:

```
php artisan elastic:migrate --force
```

Reverting Migrations
--------------------

[](#reverting-migrations)

You can either revert the last executed migrations:

```
php artisan elastic:migrate:rollback
```

or rollback a specific one:

```
php artisan elastic:migrate:rollback 2018_12_01_081000_create_my_index
```

Use the `elastic:migrate:reset` command if you want to revert all previously migrated files:

```
php artisan elastic:migrate:reset
```

Starting Over
-------------

[](#starting-over)

Sometimes you just want to start over and rollback all the changes to migrate them again immediately:

```
php artisan elastic:migrate:refresh
```

Migration Status
----------------

[](#migration-status)

You can always check which files have been already migrated and what can be reverted by the `elastic:migrate:rollback` command (the last batch):

```
php artisan elastic:migrate:status
```

Troubleshooting
---------------

[](#troubleshooting)

If you see one of the messages below, please execute the mentioned action:

- `Migration table is not yet created` - run the `php artisan migrate` command
- `Migration directory is not yet created` - create a migration file using the `elastic:make:migration` command or create a the migrations directory manually

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~40 days

Recently: every ~53 days

Total

8

Last Release

1920d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/74940341f2612b21a49dccea05d1df579fbe411b325c156636e0adaab09edd8c?d=identicon)[panytsch](/maintainers/panytsch)

---

Top Contributors

[![babenkoivan](https://avatars.githubusercontent.com/u/25812954?v=4)](https://github.com/babenkoivan "babenkoivan (37 commits)")[![panytsch](https://avatars.githubusercontent.com/u/23520972?v=4)](https://github.com/panytsch "panytsch (2 commits)")

---

Tags

phplaravelelasticsearchmigrationselastic

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/panytsch-elastic-migrations-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/panytsch-elastic-migrations-laravel/health.svg)](https://phpackages.com/packages/panytsch-elastic-migrations-laravel)
```

###  Alternatives

[babenkoivan/elastic-migrations

Elasticsearch migrations for Laravel

1962.5M6](/packages/babenkoivan-elastic-migrations)[babenkoivan/elastic-scout-driver

Elasticsearch driver for Laravel Scout

2773.8M5](/packages/babenkoivan-elastic-scout-driver)[babenkoivan/elastic-scout-driver-plus

Extension for Elastic Scout Driver

2862.8M1](/packages/babenkoivan-elastic-scout-driver-plus)[babenkoivan/elastic-client

The official PHP Elasticsearch client integrated with Laravel

544.0M6](/packages/babenkoivan-elastic-client)[babenkoivan/elastic-adapter

Adapter for official PHP Elasticsearch client

404.0M9](/packages/babenkoivan-elastic-adapter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
