def migrating_index_to_warm()

in automation/lambda/handlers/ultrawarm.py [0:0]


def migrating_index_to_warm(es, index, hot_index_age_limit):
    logger.info("Evaluating index for ultrawarm migration: " + index)
    result = es.indices.get(index=index)

    flat_json = flatten_json(result)

    is_write_index = json_search(flat_json, 'is_write_index')
    creation_date = int(int(json_search(flat_json, 'creation_date')) / 1000)
    box_type = json_search(flat_json, 'box_type')

    if is_write_index != None and not is_write_index:
        if box_type == None or box_type != 'warm':
            index_age = datetime.now() - datetime.fromtimestamp(creation_date)
            if index_age.days >= hot_index_age_limit:
                logger.info("Migrating following index to warm: " + index)
                es.indices.migrate_to_ultrawarm(index=index)