public IEnumerable <string> SimulateExecuteCommandText(ElasticSearchIndexWithRecords records, DocumentsOperationContext context) { var result = new List <string>(); if (records.InsertOnlyMode == false) { // first, delete all the rows that might already exist there result.Add(GenerateDeleteItemsCommandText(records.IndexName.ToLower(), records.DocumentIdProperty, records.Deletes)); } result.AddRange(GenerateInsertItemsCommandText(records.IndexName.ToLower(), records, context)); return(result); }
private IEnumerable <string> GenerateInsertItemsCommandText(string indexName, ElasticSearchIndexWithRecords index, DocumentsOperationContext context) { var result = new List <string>(); if (index.Inserts.Count > 0) { var sb = new StringBuilder("POST ") .Append(indexName) .AppendLine("/_bulk?refresh=wait_for"); foreach (var item in index.Inserts) { using (var json = ElasticSearchEtl.EnsureLowerCasedIndexIdProperty(context, item.TransformationResult, index)) { sb.AppendLine(ElasticSearchEtl.IndexBulkAction); sb.AppendLine(json.ToString()); } } result.Add(sb.ToString()); } return(result); }