ElasticSearch rebuild the index

If you are using ElasticSearch with Drupal 8 you most probably use https://www.drupal.org/project/elasticsearch_connector module.

If you are changing the name of the index you can face a situation when your new index is not being picked up. That happens because it doesn't have "mapping". You can solve it in two ways:
* go to index fields section and do some changes there, so it will restore the mapping
* run update index programmatically

<?php
$search_index = \Drupal\search_api\Entity\Index::load(INDEX_MACHINE_NAME);
$search_server = \Drupal\search_api\Entity\Server::load(SERVER_MACHINE_NAME);
$backend = $search_server->getBackend();
$backend->updateIndex($search_index);