# Bulk Insert error recovery

**URL:** <https://discuss.elastic.co/t/bulk-insert-error-recovery/9919>\
**Category:** Elasticsearch\
**Created:** [December 3, 2012, 10:43am UTC](https://discuss.elastic.co/t/bulk-insert-error-recovery/9919 "2012-12-03T10:43:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![smhdiu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smhdiu/32/1808_2.png) [@smhdiu](https://discuss.elastic.co/u/smhdiu)\
**Post date:** [December 3, 2012, 10:43am UTC](https://discuss.elastic.co/t/bulk-insert-error-recovery/9919/1 "2012-12-03T10:43:12Z")

</div>

hello all,

i am using elastic search bulk java api to insertion of record from legacy  
db.  
i am selecting 100 records per poll and inserting to elasticsearch.  
it is working very well and without any error.

but was wondering that what if bulk insertion to elasticsearch fails !

i have seen the api and there is a method for checking that error is there  
or not like

bulkResponse.hasFailures()

so do we have to insert entire bulk request again if there is a failure or  
we can identify that out of entire request these are  
the records which were failed.

Thanks in advanced  
Mohsin

--

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [December 3, 2012, 11:53am UTC](https://discuss.elastic.co/t/bulk-insert-error-recovery/9919/2 "2012-12-03T11:53:50Z")

</div>

Hi Mohsin,

You can find out what item has failed in the bulk response.  
You can iterate over the bulk response items and check if they failed.  
Like this:  
if (bulkResponse.hasFailures) {  
for (BulkItemResponse item : bulkResponse.items()) {  
if (item.failed()) {  
// Do something... Use item#failureMessage() to find the cause  
of the failure.  
}  
}  
}

Martijn

On 3 December 2012 21:43, mohsin husen [smhdiu@gmail.com](mailto:smhdiu@gmail.com) wrote:

> hello all,
> 
> i am using Elasticsearch bulk java api to insertion of record from legacy  
> db.  
> i am selecting 100 records per poll and inserting to elasticsearch.  
> it is working very well and without any error.
> 
> but was wondering that what if bulk insertion to elasticsearch fails !
> 
> i have seen the api and there is a method for checking that error is there  
> or not like
> 
> bulkResponse.hasFailures()
> 
> so do we have to insert entire bulk request again if there is a failure or  
> we can identify that out of entire request these are  
> the records which were failed.
> 
> Thanks in advanced  
> Mohsin
> 
> --

--  
Met vriendelijke groet,

Martijn van Groningen

--

---

<div class="post-metadata">

**Author:** ![smhdiu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smhdiu/32/1808_2.png) [@smhdiu](https://discuss.elastic.co/u/smhdiu)\
**Post date:** [December 3, 2012, 12:42pm UTC](https://discuss.elastic.co/t/bulk-insert-error-recovery/9919/3 "2012-12-03T12:42:03Z")

</div>

Thanks Martin !  
Yes that is what i wanted.... 🙂  
Cheers !

Mohsin

On Monday, 3 December 2012 11:53:50 UTC, Martijn v Groningen wrote:

> Hi Mohsin,
> 
> You can find out what item has failed in the bulk response.  
> You can iterate over the bulk response items and check if they failed.  
> Like this:  
> if (bulkResponse.hasFailures) {  
> for (BulkItemResponse item : bulkResponse.items()) {  
> if (item.failed()) {  
> // Do something... Use item#failureMessage() to find the cause  
> of the failure.  
> }  
> }  
> }
> 
> Martijn
> 
> On 3 December 2012 21:43, mohsin husen \<[smh...@gmail.com](mailto:smh...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> > hello all,
> > 
> > i am using Elasticsearch bulk java api to insertion of record from  
> > legacy  
> > db.  
> > i am selecting 100 records per poll and inserting to elasticsearch.  
> > it is working very well and without any error.
> > 
> > but was wondering that what if bulk insertion to elasticsearch fails !
> > 
> > i have seen the api and there is a method for checking that error is  
> > there  
> > or not like
> > 
> > bulkResponse.hasFailures()
> > 
> > so do we have to insert entire bulk request again if there is a failure  
> > or  
> > we can identify that out of entire request these are  
> > the records which were failed.
> > 
> > Thanks in advanced  
> > Mohsin
> > 
> > --
> 
> --  
> Met vriendelijke groet,
> 
> Martijn van Groningen

--

---

<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 6, 2017, 3:01am UTC](https://discuss.elastic.co/t/bulk-insert-error-recovery/9919/4 "2017-07-06T03:01:48Z")

</div>


