def perform_es_search()

in search/genai-101/code_examples/chat-app-code_es-8-15/backend/services/search_service.py [0:0]


def perform_es_search(query, index):
    """Performs the Elasticsearch query based on the context type."""
    logging.info(f"Starting Elasticsearch search for query: {query}")

## TODO USERS ENTER QUERY CODE HERE
    es_query = {

    }

    try:
        result = es_client.search(index="restaurant_reviews", body=es_query)

    except Exception as e:
        # If generated query fails fallback to backup query
        logging.error(f"Error in Elasticsearch search: {str(e)}")
        raise

    # logging.info(f"elasticsearch results: {result}")
    hits = result["hits"]["hits"]
    logging.info(f"number of hits: {len(hits)}")
    return hits