def create_default_index_and_alias(es_client, alias_name, index_body=None):
    default_alias_name = alias_name
    logger.info("Default alias name: {}".format(default_alias_name))
    physical_index = get_index_from_alias(es_client, default_alias_name)
    if not physical_index:
        with Timer('Creating Index and Alias', logger=logger.info):
            index_name = new_index_from_name(default_alias_name)
            es_client.indices.create(index_name, body=index_body)
            es_client.indices.put_alias(default_alias_name, index_name)
            es_client.indices.put_alias(default_alias_name + ".write", index_name)
    else:
        logger.info("Alias {} exist mapped to {}".format(alias_name, physical_index))
def create_new_write_index(es_client, alias_name, new_index_config=None):

    with Timer('Create Write Index and change Alias', logger=logger.info):
        write_alias = alias_name + ".write"

        #Get the current Real Index for the write alias
        current_indexes = get_index_from_alias(es_client, write_alias)
        current_index = current_indexes[0]

        #Create a new empty index for writes
        new_index_name = new_index_from_name(alias_name)
        es_client.indices.create(new_index_name, new_index_config)
        es_client.indices.flush()
        #Change the write alias to the new index for writes
        es_client.indices.update_aliases({"actions": [
            {"remove": {"index": current_index, "alias": write_alias}},
            {"add": {"index": new_index_name, "alias": write_alias}}
        ]})
        es_client.indices.flush()