public async Task InsertDocuments(params string[] documents) { StringBuilder bulkBody = new StringBuilder(); foreach (string source in documents) { var actionObject = new { create = new { _index = _indexName, _type = _typeName, _id = _documentsIdGenerator.NextId(), } }; var action = JSON.Serialize(actionObject); bulkBody.AppendLine(action); bulkBody.AppendLine(JSON.EnsureSingleLine(source)); bulkBody.AppendLine(); } var response = await _elasticClient.BulkPutAsync <string>(_indexName, _typeName, bulkBody.ToString(), x => x.Refresh(Refresh.WaitFor)); ThrowIfError(response); }