refactor with elasticsearch plugin and improved template