def create_elastic_index()

in app/services/elasticsearch.py [0:0]


def create_elastic_index(es_client: Elasticsearch, index_name: str) -> None:
    """
    Delete the Elasticsearch index if it exists, then create a new one.

    Args:
        es_client (Elasticsearch): The Elasticsearch client.
        index_name (str): The name of the index to be created.
    """
    if es_client.indices.exists(index=index_name):
        es_client.indices.delete(index=index_name)
        logger.info(f"🗑️  Deleted existing Elasticsearch index: {index_name}")

    es_client.indices.create(index=index_name)
    logger.info(f"✨ Created new Elasticsearch index: {index_name}")