The spell only ends for the target of the dispel magic spell
This was clarified in the June 2016 Rules Answers article, later included on page 14 of the 2016 Sage Advice Compendium, and can be found here on D&D Beyond:
If dispel magic targets the magical effect from bless cast by a cleric, does it remove the effect on all the targets? Dispel magic ends a spell on one target. It doesn’t end the same spell on other targets.
Since it leaps to a creature "of your choice", you don't have to target another creature if you don't want to
The description of the green-flame blade cantrip (SCAG, p. 143; TCoE, p. 107) has somewhat similar wording to that of chaos bolt:
You brandish the weapon used in the spell’s casting and make a melee
attack with it against one creature within 5 feet of you. On a hit,
the target suffers the weapon attack’s normal effects, and you can
cause green fire to leap from the target to a different creature of
your choice that you can see within 5 feet of it. The second
creature takes fire damage equal to your spellcasting ability
modifier.
Before the 2020 errata to the Sword Coast Adventurer's Guide, the relevant line of the spell description read "[...] and green fire leaps to [...]" (which is even more similar to that of chaos bolt); the errata changed that phrase to "[...] and you can cause green fire to leap to [...]" instead.
Rules designer Jeremy Crawford stated the following about green-flame blade in an unofficial tweet from November 2015:
What does the leap effect of green-flame blade do if there are no hostile targets nearby? Does it jump to allies?
The intent is that you can choose no one. If you can't see, you can't choose anyway, and the flame halts
Given the similar wording to the description of chaos bolt (XGtE, p. 151; GGtR, p. 67), it seems safe to assume chaos bolt would work the same way, so if there are no enemies within that range of chaos bolt, you don't need to target someone else.
This is even clearer after the update to the text of green-flame blade (due to the use of "can") - but even otherwise, the specification that it leaps only to a target "of your choice" seems sufficient to indicate that you can choose no target at all. The same logic extends to chaos bolt.
This makes sense to me. Given that if the energy of chaos bolt does leap to another, you choose what creature it leaps to, it makes sense that you can use the same control over targeting to prevent it from jumping to any creature (e.g. by having it fizzle harmlessly against the ground).
Best Answer
The only special rules we have for swarms are the following:
So as far as the rules are concerned, swarms don't have any exception to the usual targeting rules, so there is nothing that would make spells hit the player. D&D 5e doesn't have any rules about firing into melee, or anything else which would cause someone to hit a different target to the one they aimed at.
However, since the swarm is swarming around the player, at least some of the swarm will have the player's body between them and any given spellcaster, providing the swarm with some degree of cover. A case can be made for different degrees of cover:
The rules for cover are on page 74 of the Player's Basic Rules; I won't write them all out here, but half cover gives +2 to AC and Dex saves, three-quarters cover gives +5 to AC and Dex saves, and you can't target anything that has total cover. How you rule is up to you, of course, but I'd probably go with half cover.
Of course, all of the above needs the usual disclaimer: You are the GM. You can houserule however you want, so if you think players should be at risk of hitting their allies, you're free to make that rule. I will say that you should be careful about doing this, because swarms can be very tricky for some groups to fight, particularly at low levels.