refactor elasticsearch into a method
add onKill handling into elasticsearch