# Timeout in Bulk operation when deleting documents

**URL:** <https://discuss.elastic.co/t/timeout-in-bulk-operation-when-deleting-documents/51222>\
**Category:** Elasticsearch\
**Created:** [May 28, 2016, 1:29pm UTC](https://discuss.elastic.co/t/timeout-in-bulk-operation-when-deleting-documents/51222 "2016-05-28T13:29:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThomasD3](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@ThomasD3](https://discuss.elastic.co/u/ThomasD3)\
**Post date:** [May 28, 2016, 1:29pm UTC](https://discuss.elastic.co/t/timeout-in-bulk-operation-when-deleting-documents/51222/1 "2016-05-28T13:29:18Z")

</div>

I have a list of document IDs I want to delete.

The naive way works well:

> foreach (var Id in IDs)  
> {  
> EC.Delete(Id);  
> }

but it is insanely slow.

So I tried this:

> EC.DeleteMany(IDs);

which doesn't seem to do anything at all; it certainly doesn't delete the documents.

Then I tried the bulk approach:

> var Bulk = new BulkDescriptor();  
> foreach (var R in RecordIDs)  
> {  
> Bulk.Index(\_ =\> \_.Document(new IndexedData { Id = R }));  
> }

And now this one fails:

> "Invalid NEST response built from a unsuccessful low level call on POST: /\_bulk\r\n# Audit trail of this API call:\r\n - BadResponse: Node: [http://127.0.0.1:9200/](http://127.0.0.1:9200/) Took: 00:01:00.1360093\r\n - MaxTimeoutReached: Took: -736111.13:10:20.1704195\r\n# OriginalException: System.Net.WebException: The request was aborted: The request was canceled.\r\n at System.Net.ConnectStream.InternalWrite(Boolean async, Byte buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)\r\n at System.Net.ConnectStream.Write(Byte buffer, Int32 offset, Int32 size)\r\n at  
> ...

So, the problem is a timeout, but this is on an idle development computer with elastic running on the same machine.

Could it be that bulk operation do no handle a large number of operation? (1.2million in this case).

Also, is there a better way to do this? creating an empty class for every command, just to put the ID in it seems incredibly wasteful when I could just pass the ID.

---

<div class="post-metadata">

**Author:** ![ThomasD3](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@ThomasD3](https://discuss.elastic.co/u/ThomasD3)\
**Post date:** [May 28, 2016, 2:18pm UTC](https://discuss.elastic.co/t/timeout-in-bulk-operation-when-deleting-documents/51222/2 "2016-05-28T14:18:11Z")

</div>

I have now broken down the operation into chunks of 5k records to test:

> ```
> var Bulk = new BulkDescriptor();
> var Count = 0;
> IBulkResponse Result;
> foreach (var R in RecordIDs)
> {
> Bulk.Delete<IndexedData>(_ => _.Document(new IndexedData { Id = R }));
> Count++;
> if (Count % 5000 == 0)
> {
> Result = EC.Bulk(Bulk);
> Bulk = new BulkDescriptor();
> }
> }
> 
> ```

but it is insanely slow as well: 10minutes to remove 1.2m records vs. 10-15 seconds when we used Lucene. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:48pm UTC](https://discuss.elastic.co/t/timeout-in-bulk-operation-when-deleting-documents/51222/3 "2017-07-05T22:48:20Z")

</div>


