Bulk Insert error recovery

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

--

1 Like

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 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

--

1 Like

Thanks Martin !
Yes that is what i wanted.... :slight_smile:
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 <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

--