Minecraft wiki entry for Combat, associated text: If the player must melee a guardian, they should try to corner it and hope for the best; or else try to trick it into swimming within melee range repeatedly.