Replace addToHistory function to store histories to elasticsearch.