refactored to move duplicated code to new protected methods in ElasticsearchPersistWriter