There’s a couple options:
- Panic them. For all that elephants are enormous, they spook quite easily (hence the whole thing about mice). War pigs, were quite effective against them, but any large group of fast-moving animals that make noise would do the trick if herded toward them. Incendiary weapons are also very effective, because elephants do not like fire.
- Loosen your formation. Rather than stand in front of them, let the elephants pass through your lines, surround them at a good distance, and then stab the elephants in their legs/belly, which can either bring them down or cause them to panic.
- A mix of long spears and throwing weapons. If your spears can outrange the elephant’s tusks, you can jab them good before they can gore or trample you. Combine that with throwing weapons to wound the elephant or their mahouts.