World champions Spain have come back from two goals down to defeat Chile in a friendly in Switzerland.