@@ -27,6 +27,7 @@ Check out its [features](#features)!
27
27
* [ Console commands] ( #console-commands )
28
28
* [ Search rules] ( #search-rules )
29
29
* [ Available filters] ( #available-filters )
30
+ * [ Zero downtime migration] ( #zero-downtime-migration )
30
31
* [ Debug] ( #debug )
31
32
32
33
## Tutorial
@@ -41,6 +42,7 @@ There are information about Elasticsearch installation and the package usage exa
41
42
* A possibility to add a new field to an existing mapping [ automatically] ( #configuration ) or using [ the artisan command] ( #console-commands ) .
42
43
* Lots of different ways to implement your search algorithm: using [ search rules] ( #search-rules ) or a [ raw search] ( #usage ) .
43
44
* [ 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.
44
46
45
47
## Requirements
46
48
@@ -262,6 +264,7 @@ elastic:create-index | `index-configurator` - The index configurator class | Cre
262
264
elastic: update-index | ` index-configurator ` - The index configurator class | Updates settings and mappings of an Elasticsearch index.
263
265
elastic: drop-index | ` index-configurator ` - The index configurator class | Drops an Elasticsearch index.
264
266
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.
265
268
266
269
For detailed description and all available options run ` php artisan help [command] ` in the command line.
267
270
@@ -376,6 +379,29 @@ whereRegexp($field, $value, $flags = 'ALL') | whereRegexp('name.raw', 'A.+') | F
376
379
377
380
In most cases it's better to use raw fields to filter records, i.e. not analyzed fields.
378
381
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
+
379
405
## Debug
380
406
381
407
There are two methods that can help you to analyze results of a search query:
0 commit comments