def METHOD_NAME(context, filter_node):
    from corehq.apps.case_search.dsl_utils import unwrap_value
    if (isinstance(filter_node, BinaryExpression)
    and serialize(filter_node.left) == "@case_id" and filter_node.op == EQ):
        # case id is provided in query i.e @case_id="b9eaf791-e427-482d-add4-2a60acf0362e"
        case_ids = unwrap_value(filter_node.right, context)
        return [case_ids] if isinstance(case_ids, str) else case_ids
    else:
        from corehq.apps.case_search.filter_dsl import build_filter_from_ast
        es_filter = build_filter_from_ast(filter_node, context)
        es_query = CaseSearchES().domain(context.domain).filter(es_filter)
        if es_query.count() > MAX_RELATED_CASES:
            new_query = serialize(filter_node)
            raise TooManyRelatedCasesError(
                gettext("The related case lookup you are trying to perform would return too many cases"),
                new_query
            )
        return es_query.scroll_ids()