I'm looking at the list of battles involving war elephants
The Battle of Ipsus wikip page, a conflict between some of the successor states of Alexander the great, has an interesting passage on elephant-cavalry interactions:
"The ancient sources repeatedly emphasise the effect of elephants on horses, which are alarmed by the smell and noise of elephants and are loathe to approach them. Demetrius would not have been able to take his horses through the line of elephants, nor manoeuvre around such a large quantity of elephants."
The Battle of Heraclea shows an even more effective use of elephants during the Pyrrhic War:
"Unable to make any significant gains in action, Pyrrhus deployed his elephants, held in reserve until now. The Roman cavalry was threatening his flank too strongly. Aghast at the sight of these strange and brooding creatures which none had seen before, the horses galloped away and threw the Roman legion into rout."
You'll notice in the next battle Rome deployed many anti-elephant devices and anti-elephant chariots. They famously mastered anti-elephant tactics come the Battles of Zama at the end of the 2nd Punic War.
It seems elephants has success against cavalry were used most effectively against close formation infantry, using their weight to break lines in a way horses could not, being the "shock troops" of these ancient battles. The wiki page on War elephants, tactics section is useful on this. You'll notice I concentrated on the classical period, but the list doesn't stop until the 18th century and they were even used in Italy up to the 13th century.
I looked at the indian battles and they seem to mostly fill the role of shock troops again, but at the Battle of Ngasaunggyan they had success against cavalry (it doesn't say the composition of the mongol armies, but I bet there were many cavalry) until countered by archery (unfortunately for the elephants, the mongols being feared and successful horse archers).