FriendsOfSymfony/FOSElasticaBundle — pull request #264 by kostiklv (2013-04-01 17:47:43+00:00)
Title: [WIP] Using aliases to allow reindexing with atomic alias switching

Currently `populate` command resets the index, and so it's not available while being reindexed, meaning if you need to reindex in production (due to mapping changes or whatever else), you site (or at least search) will be down.

This PR makes use of ES aliases to fix the above problem. `populate` command now creates a new index, populates it and then updates the alias to point to the new index in an atomic way. The old index is automatically deleted after a successful alias update.

To achieve this, I had to extend `Elastica_Index` class to add `overrideName` method (which is a setter for index name). Since this bundle used `Elastica_Client` as the factory service for creating index instances, and I needed to make it instantiate a different class (`ElasticaDynamicIndex`), I had to refactor the way the index instances are being created. I figured out that the `IndexManager` is the best candidate for the job of creating index instances. (I'm also going to submit PR to Elastica to update the original `Elastica_Index` class, but nevertheless, I think the refactoring of `IndexManager` to build the indexes makes sense).

I have also removed injecting of index settings into `Resetter` and made it use `IndexManger` for everything related to index configuration.

Also, to avoid any confusion between index service name (as defined in YML as config's key), ES actual index name (defined in `index_name` attribute) and index alias (introduced in this PR), I had renamed the references of indexes (in variable names) to `key` instead of `name` where applicable.

The functionality is optional. To use it, add `use_alias: true` into index configuration (YML). Note, that to switch from using index_name directly to using an alias, you have to first manually delete the existing index (otherwise the alias can't be set because an index with such name already exists). Switching back from using alias to plain index is easy - `Resetter` will just delete the index by its alias and then recreate it as plain index.

Please review the code. If the concept is fine, I'll update the tests and documentation.