def query_for_order(query, order):
    """
    Applies transformations on the ES query based on the search order.

    Order is assumed to be a string with the name of a field with an optional
    hyphen to indicate descending sort order.
    """
    if order == "":  # relevance should not sort
        return query

    field = order[order.find("-") + 1 :]
    sort_info = {
        field: {
            "order": "desc" if order.startswith("-") else "asc",
            "unmapped_type": "long",
        }
    }
    query = query.sort(sort_info)
    return query