def build_query()

in utils/es.py [0:0]


def build_query(dimensions_exist: {}, dimensions_missing: []):
    """
    Build query to retrieve document based on the dimensions.
    :param dimensions_exist: Dictionary containing field and field value of the dimensions that exist in the document.
    :param dimensions_missing: Dictionary of the dimension fields missing in the document.
    :return: query.
    """
    query = {
        "bool": {
            "must": [],
            "must_not": []
        }
    }
    for field in dimensions_exist:
        term = {
            "term": {
                field: dimensions_exist[field]
            }
        }
        query["bool"]["must"].append(term)

    for field in dimensions_missing:
        exists = {
            "exists": {
                "field": field
            }
        }
        query["bool"]["must_not"].append(exists)

    return query