def atomic_swap(alias_name, new_index_name, index_client):
logging.info('<STR_LIT>')<EOL>if index_client.exists_alias(name=alias_name):<EOL><INDENT>old_index_name = get_index_from_alias(alias_name, index_client)<EOL>logging.info('<STR_LIT>')<EOL>actions = {'<STR_LIT>': [<EOL>{'<STR_LIT>': {'<STR_LIT:index>': old_index_name, '<STR_LIT>': alias_name}},<EOL>{'<STR_LIT>': {'<STR_LIT:index>': new_index_name, '<STR_LIT>': alias_name}}<EOL>]}<EOL>index_client.update_aliases(body=actions)<EOL>index_client.delete(index=old_index_name)<EOL><DEDENT>else:<EOL><INDENT>logging.info('<STR_LIT>')<EOL>actions = {'<STR_LIT>': [<EOL>{'<STR_LIT>': {'<STR_LIT:index>': new_index_name, '<STR_LIT>': alias_name}}<EOL>]}<EOL>index_client.update_aliases(body=actions)<EOL><DEDENT>
Points an alias to a new index, then delete the old index if needed

    Uses client.update_aliases to perform this with zero downtime

    Args:
        alias_name (str) Name of the alias
        new_index_name (str) The new index that the alias should point to
        index_client (Elasticsearch.IndicesClient) Elasticsearch index client