babenkoivan / elastic-migrations

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

Invalid Argument Exception on `elastic:migrations:fresh` #38

Closed chrisribal closed 2 years ago

chrisribal commented 2 years ago
Software Version
PHP 8.0.13
Elasticsearch 7.15.1
Laravel 8.68.1

Describe the bug I tried to start over my elasticsearch migrations by running php artisan elastic:migrate:fresh. ElasticSearch responds with the following error:

   Elasticsearch\Common\Exceptions\BadRequest400Exception 

  {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Wildcard expressions or all indices are not allowed"}],"type":"illegal_argument_exception","reason":"Wildcard expressions or all indices are not allowed"},"status":400}

  at vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:693
    689▕             $exception = new ScriptLangNotSupportedException($responseBody. $statusCode);
    690▕         } elseif ($statusCode === 408) {
    691▕             $exception = new RequestTimeout408Exception($responseBody, $statusCode);
    692▕         } else {
  ➜ 693▕             $exception = new BadRequest400Exception($responseBody, $statusCode);
    694▕         }
    695▕ 
    696▕         $this->logRequestFail($request, $response, $exception);
    697▕ 

      +25 vendor frames 
  26  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

Current behavior NO Index is being freshly migrated, instead Exception is thrown.

Expected behavior ALL Indexes should be freshly migrated.

iget-master commented 2 years ago

To allow deleting all indexes using wildcard you must disable the action.destructive_requires_name option.

Maybe this package should read all migrations to enumerate the created indexes and delete it one by one to avoid disabling this safety option? @babenkoivan

Or alternatively disabling the option at runtime (if enabled) and enable back.

chrisribal commented 2 years ago

@iget-master I'm not sure, if that's also the case for ElasticSearch 7.x. The documentation seems to state, that destructive wildcard queries are allowed by default, but can be disabled.

To delete all indices, use _all or * . To disallow the deletion of indices with _all or wildcard expressions, set the action.destructive_requires_name cluster setting to true. https://www.elastic.co/guide/en/elasticsearch/reference/7.17/indices-delete-index.html

Additionally, i tried adding action.destructive_requires_name=false into my Laravel Sail's docker-compose.yml, but it's still not working.

Anyway, looping through the existing indices and deleting them one by one would be a better way, i guess. As @babenkoivan seems to be busy, i'll try to submit a PR.

babenkoivan commented 2 years ago

Hi there! It is not very optimal to delete migrations one by one when running tests, that's why this command exists. I'd recommend figuring out why changing the action.destructive_requires_name config doesn't make any effect, but alternatively, you can run elastic:migrate:refresh, which does exactly what you want 😉

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days