babenkoivan / elastic-migrations

Elasticsearch migrations for Laravel
MIT License
187 stars 32 forks source link

Improved documentation #42

Closed maxgfb closed 2 years ago

maxgfb commented 2 years ago

I want to add a field to an existing index

I believe I should use Index::putMapping

Do I need to include the full mapping copied from the Index::create or do I only include the new field?

Using your example

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

What do you put in the down() method to roll this back?

babenkoivan commented 2 years ago

Hi @maxgfb,

Do I need to include the full mapping copied from the Index::create or do I only include the new field?

You can only specify the new fields. In fact, ES will not allow you to modify already existing fields.

What do you put in the down() method to roll this back?

Probably nothing in this case because it's not possible to delete existing fields from an index.