cleanup of elasticsearch api, remove repeats, consolidate some repeated functions to get it more DRY