sort search results by elasticsearch order, consolidate duplicate code