spring-data-jest
spring-data-jest copied to clipboard
Is there a way to get bulk request failed items via save all or in the exception object
Hi , I am using spring data jest to index some of my bulk data sets using spring data saveAll method . THis breaks sometimes and throws an exception as below
om.github.vanroy.springdata.jest.exception.JestElasticsearchException: Cannot execute jest action , response code : 200 , error : One or more of the items in the Bulk request failed, check BulkResult.getItems() for more information. , message : null at com.github.vanroy.springdata.jest.mapper.DefaultErrorMapper.mapError(DefaultErrorMapper.java:30) at com.github.vanroy.springdata.jest.JestElasticsearchTemplate.execute(JestElasticsearchTemplate.java:1218) at com.github.vanroy.springdata.jest.JestElasticsearchTemplate.execute(JestElasticsearchTemplate.java:1208) at com.github.vanroy.springdata.jest.JestElasticsearchTemplate.bulkIndex(JestElasticsearchTemplate.java:697) at org.springframework.data.elasticsearch.repository.support.AbstractElasticsearchRepository.saveAll(AbstractElasticsearchRepository.java:184)
This is fine but could there be a way to get the bulk result object in the exception throws so the calling client can be aware of how to handle and debug the same .
Hi @gauravbrills ,
You can catch JestElasticsearchException and use getResult to retrieve result data.
Exemple :
try {
result = elasticsearchTemplate. bulkIndex(XXX)
} catch(JestElasticsearchException e) {
((BulkResult) e.getResult()).getItems()
}
Please keep me in touch if it works for you.
@VanRoy Ya I am aware of the above approach and doing by using the same in my custom repository . but could we ha some custom method to do this some kind of abstraction in a a jest specific repository . Though I agree the design of jest is to follow core spring data elasticsearch interfaces .
Though not a major issue ..
@gauravbrills Indeed, I try to stay close as possible to SDE. But your idea could be interested, I will think about it.
Thanks for your feedback. Julien.