public void Delete <T>(Id id) where T : class { DeletesMeter.Mark(); _pendingSize++; Logger.Debug("Deleting document {0}", id.GetString(_client.ConnectionSettings)); _pendingDocs.Delete <T>(x => x.Id(id)); }
/// <summary> /// Deletes the specified documents. /// </summary> /// <param name="items">The items.</param> public override void Delete(ref IEnumerable <ContentBatchOperationDescriber> items) { var descriptor = new BulkDescriptor(); _ = descriptor.Refresh(Refresh.WaitFor); foreach (var item in items) { item.State = ContentDeletionStateEnum.SucceededIndexDeletion; var document = (item.Content as Document) !; foreach (var field in document.Fields) { var indexId = Connection.GetIndexId(field.Key); _ = descriptor.Delete <object>(op => op .Index(indexId) .Id(document.Id) ); } } var response = Connection.Client.Bulk(descriptor); if (response.Errors && response.ItemsWithErrors.Any()) { foreach (var errorItem in response.ItemsWithErrors) { var item = items.First(i => i.Content.Id.ToString(CultureInfo.InvariantCulture) == errorItem.Id && errorItem.Type == "_doc"); item.State = ContentDeletionStateEnum.ErrorIndexDeletion; item.Error = errorItem.Error; } } }
public void RemoveByListId(List <string> lst_id) { int spl = 100; for (int i = 0; i <= lst_id.Count / spl; i++) { var tmp = lst_id.Skip(i * spl).Take(spl); if (tmp.Count() > 0) { var bulk = new BulkDescriptor(); foreach (var id in tmp) { bulk.Delete <PhanQuyen>(b => b.Id(id)); } var re = client.Bulk(bulk); } } RemoveByQuery(lst_id); }
public async Task <bool> DeleteAsync(IList <string> ids, Refresh refresh = Refresh.WaitFor) { if (!ids.HasItems()) { throw new ArgumentException(string.Format(Utils.ARGUMENT_EMPTY_LIST_MESSAGE, nameof(ids)), nameof(ids)); } var descriptor = new BulkDescriptor(); foreach (var id in ids.Where(x => !string.IsNullOrWhiteSpace(x))) { descriptor.Delete <T>(x => x .Id(id)); } descriptor.Refresh(refresh); var response = await _client.BulkAsync(descriptor); return(response.IsValid); }
public async Task DeleteAsync(IList <long> ids) { var descriptor = new BulkDescriptor(); foreach (var id in ids) { descriptor.Delete <T>(x => x .Id(id)) .Refresh(Refresh.WaitFor); } IBulkResponse result = await this._esClient.BulkAsync(descriptor); if (!result.IsValid) { this._logger.LogError(result.OriginalException, $"Error deleting entities of type {this._entityType} from index {this._entityIndex}.", new[] { result }); throw result.OriginalException; } this._logger.LogTrace($"Deleted {result.Items.Count} entities of type {this._entityType} from index {this._entityIndex}.", new[] { result }); }
public void Run(IEnumerable <DocChange <TDoc> > changes) { var descriptor = new BulkDescriptor(); var indexName = "WaterPointElasticSearch"; foreach (var c in changes) { switch (c.Type) { case DocChangeTypes.EditOrCreate: descriptor.Index <TDoc>(doc => doc .Document(c.Doc) .Index(indexName) .Routing(c.Doc.OrganizationId.ToString(CultureInfo.InvariantCulture))); break; case DocChangeTypes.Remove: descriptor.Delete <TDoc>(doc => doc .Document(c.Doc) .Index(indexName)); break; } } var response = _client.Bulk(descriptor); if (!response.Errors) { return; } var errors = response.ItemsWithErrors .Select(e => new Exception(e.Error.Reason)) .ToList(); throw new AggregateException(errors); }