# Identify, save and resend failed requests in BulkProcessor

**URL:** <https://discuss.elastic.co/t/identify-save-and-resend-failed-requests-in-bulkprocessor/79732>\
**Category:** Elasticsearch\
**Created:** [March 23, 2017, 11:00am UTC](https://discuss.elastic.co/t/identify-save-and-resend-failed-requests-in-bulkprocessor/79732 "2017-03-23T11:00:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![khat33b](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/khat33b/32/16644_2.png) [@khat33b](https://discuss.elastic.co/u/khat33b)\
**Post date:** [March 23, 2017, 11:00am UTC](https://discuss.elastic.co/t/identify-save-and-resend-failed-requests-in-bulkprocessor/79732/1 "2017-03-23T11:00:11Z")

</div>

I am using `BulkProcessor` to index data to Elasticsearch 5.2. In my requests, there are a couple of failures and I get `response.hasFailures()` as `true`. How do I extract the failed requests, save them to a file and resend them in another request?

My `BulkProcessor` is built like this:

```
BulkProcessor bulkProcessor = BulkProcessor.builder(client, new BulkProcessor.Listener() {
	@Override
	public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
		System.out.println("Bulk execution completed ["+ executionId + "].\n" +
                "Took (ms): " + response.getTookInMillis() + "\n" +
                "Failures: " + response.hasFailures() + "\n" + 
                "Count: " + response.getItems().length);
	}
	@Override
	public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
		System.out.println("Bulk execution failed [" + executionId + "].\n" + failure.toString());
	}
	@Override
	public void beforeBulk(long executionId, BulkRequest request) {
	}
})
.setBulkActions(-1)
.setBulkSize(new ByteSizeValue(15, ByteSizeUnit.MB))
.setFlushInterval(TimeValue.timeValueSeconds(10))
.setConcurrentRequests(0)
.build();
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 23, 2017, 12:47pm UTC](https://discuss.elastic.co/t/identify-save-and-resend-failed-requests-in-bulkprocessor/79732/2 "2017-03-23T12:47:51Z")

</div>

You need to maintain a Map of the operations you sent to the bulk.

If successful clean that map. If not, retrieve the operation from the map.

Note that it can consume some space in your HEAP then...

---

<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:** [April 20, 2017, 12:47pm UTC](https://discuss.elastic.co/t/identify-save-and-resend-failed-requests-in-bulkprocessor/79732/3 "2017-04-20T12:47:52Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
