def METHOD_NAME(self, result) -> Optional[int]:
    if getattr(result, "body", None) and "hits" in result.body:  # ES >= 8
        return result.body["hits"].get("total", {}).get("value")
    elif isinstance(result, dict) and "hits" in result and "total" in result["hits"]:
        return (
            result["hits"]["total"]["value"]
            if isinstance(result["hits"]["total"], dict)
            else result["hits"]["total"]
        )