import logging


def convert_to_es(scan_result: tuple[dict, str]) -> dict:
    """
    Converts a dictionary with an IP as a key to a dictionary with the IP as a value, which helps elasticsearch queries.
    Input:
        - scan_result: a tuple with the scanned dictionary as the first element and the IP address of the host as the second.
    Output: a dictionary with the IP as a value.
    """
    logging.info("Converting the scan output to one that elasticsearch parses better.")
    data = {}
    scan_dict = scan_result[0]
    keys = list(scan_dict.keys())
    ip = scan_result[1]
    if ip in keys and 'ports' in scan_dict[ip]:
        data = scan_dict
        data['scan_results'] = scan_dict[ip]
        data['host'] = {}
        data['host']['ip'] = ip
        data.pop(ip)
    return data