def METHOD_NAME(agency_type, agency_tier, record: dict) -> Optional[str]:
    """Dictionary key order impacts Elasticsearch behavior!!!"""
    if record[f"{agency_type}_{agency_tier}_agency_name"] is None:
        return None
    result = {"name": record[f"{agency_type}_{agency_tier}_agency_name"]}
    if f"{agency_type}_{agency_tier}_agency_abbreviation" in record:
        result["abbreviation"] = record[f"{agency_type}_{agency_tier}_agency_abbreviation"]
    if f"{agency_type}_{agency_tier}_agency_code" in record:
        result["code"] = record[f"{agency_type}_{agency_tier}_agency_code"]
    result["id"] = record[f"{agency_type}_toptier_agency_id"]
    return json.dumps(result)