Refactor elasticsearch tasks