This gist assums that you are running a Ruby on Rails project and you are using the elasticsearch-rails gem to operate with your Elasticsearch cluster.
This script is using the Elasticsearch Index Aliases and Reindex API to provide a way for applying zero downtime index mapping changes (adding, deleting or modifying a field).
Let's say that you have an Article model which by default references an articles index in Elasticsearch. And lets assume that articles is an alias to a timestamped index articles_20180101000001.
Running the script will:
- Create a new timestamped index
articles_20180101000002 - Will use the Reindexing API to copy all documents from
articles_20180101000001toarticles_20180101000002 - Will alias
articles_20180101000002toarticles. - Will delete
articles_20180101000001