from typing import Dict
from typing import Optional


def get_query_from_dict(data: Dict[str, Optional[str]]) -> str:
    """
    Prepare a query to be passed to ES based on incoming
    key-value pairs in a dict
    :param data: key-value pairs to use for searching in ES
    :return: query string
    """
    return " AND ".join(
        [f"{key}:{value}" for key, value in data.items() if value is not None]
    )