我目前正在使用批量请求将实体从DBMS迁移到Elasticsearch,但是我希望能够确定操作期间哪些特定实体失败了(无需在操作后查询Elastic)。
我注意到BulkItemResponse.Failure
类具有ID_FIELD
,但这似乎是操作,而不是文档。
响应中是否可以使用任何字段来检索失败文档的字段?
最佳答案
阅读了Elasticsearch论坛之后,似乎只能在批量请求中检索文档的索引,而不能检索文档的内容
https://discuss.elastic.co/t/way-to-re-index-failed-documents-using-bulkprocessor/33736/3
作为记录,这是我从批量响应中提取失败项目ID的方式:
List<Integer> processBulkResponse(BulkResponse bulkResponse) {
List<Integer> failures = new ArrayList<>();
for (BulkItemResponse bulkItemResponse : bulkResponse) {
if (bulkItemResponse.isFailed()) {
failures.add(bulkItemResponse.getItemId());
}
}
return failures;
}
关于java - 当Elasticsearch批量操作发生故障时,如何获取文档字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54463110/