Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit 0de0b4e

Browse files
committed
Described zero downtime migration in the README file
1 parent 4f0f336 commit 0de0b4e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Check out its [features](#features)!
2727
* [Console commands](#console-commands)
2828
* [Search rules](#search-rules)
2929
* [Available filters](#available-filters)
30+
* [Zero downtime migration](#zero-downtime-migration)
3031
* [Debug](#debug)
3132

3233
## Tutorial
@@ -41,6 +42,7 @@ There are information about Elasticsearch installation and the package usage exa
4142
* A possibility to add a new field to an existing mapping [automatically](#configuration) or using [the artisan command](#console-commands).
4243
* Lots of different ways to implement your search algorithm: using [search rules](#search-rules) or a [raw search](#usage).
4344
* [Various filter types](#available-filters) to make a search query more specific.
45+
* [Zero downtime migration](#zero-downtime-migration) from an old index to a new index.
4446

4547
## Requirements
4648

@@ -262,6 +264,7 @@ elastic:create-index | `index-configurator` - The index configurator class | Cre
262264
elastic:update-index | `index-configurator` - The index configurator class | Updates settings and mappings of an Elasticsearch index.
263265
elastic:drop-index | `index-configurator` - The index configurator class | Drops an Elasticsearch index.
264266
elastic:update-mapping | `model` - The model class | Updates a model mapping.
267+
elastic:migrate | `model` - The model class, `target-index` - The index name to migrate | Migrates model to another index.
265268

266269
For detailed description and all available options run `php artisan help [command]` in the command line.
267270

@@ -376,6 +379,29 @@ whereRegexp($field, $value, $flags = 'ALL') | whereRegexp('name.raw', 'A.+') | F
376379

377380
In most cases it's better to use raw fields to filter records, i.e. not analyzed fields.
378381

382+
## Zero downtime migration
383+
384+
As you might know, you can't change the type of already created field in Elasticsearch.
385+
The only choice in such case is to create a new index with necessary mapping and import your models into the new index.
386+
A migration can take quite a long time, so to avoid downtime during the process the driver reads from the old index and writes to the new one.
387+
As soon as migration is over it starts reading from the new index and removes the old index.
388+
This is how the artisan `elastic:migrate` command works.
389+
390+
Before you run the command, make sure that your index configurator uses the `ScoutElastic\Migratable` trait.
391+
If it's not, add the trait and run the artisan `elastic:update-index` command using your index configurator class name as an argument:
392+
393+
```php
394+
php artisan elastic:update-index App\\MyIndexConfigurator
395+
```
396+
397+
When you are ready, make changes in the model mapping and run the `elastic:migrate` command using the model class as the first argument and desired index name as the second argument:
398+
399+
```php
400+
php artisan elastic:migrate App\\MyModel my_index_v2
401+
```
402+
403+
Note, that if you need just to add new fields in your mapping, use the `elastic:update-mapping` command.
404+
379405
## Debug
380406

381407
There are two methods that can help you to analyze results of a search query:

0 commit comments

Comments
 (0)