improve elasticsearch function