Phelps did it for 4 Olympics, still the greatest on that alone.
No shame being 2nd to Phelps though, although I hate comparing sports. There are others that are up there too, a couple of gymnasts, Steve Redgrave (rowing), etc.
Phelps competes in a sport that maybe 10-15 countries take seriously. Literally every country on earth can compete in athletics, not just rich western ones.
For phelps to win 9 gold, he only has to swim 2 distances in a couple categories. For bolt to win 9 gold at s single Olympics, he'd need to compete and win at every distance from 100m up to marathon.
Until they start allowing hopping, skipping, and backwards running events for athletics comparing the 2 on medal counts is geniused.
Bolt is easily the best Olympian of all time. His only competition will be Ruddisha after Tokyo, who will likely complete a treble in the 800 and 1500m. Mo Farah could do so as well, but IMO he's likely going to be running marathons by Tokyo instead of the 5 and 10k