【问题标题】:How to get document fields when a failure happens in an Elasticsearch bulk operation?Elasticsearch 批量操作发生故障时如何获取文档字段?
【发布时间】:2019-02-01 22:23:21
【问题描述】:

我目前正在使用批量请求将实体从 DBMS 迁移到 Elasticsearch,但我希望能够确定哪些特定实体在操作期间失败(无需在操作后查询 Elastic)。 我注意到BulkItemResponse.Failure 类有一个ID_FIELD,但这似乎是动作,而不是文档。

响应中是否有任何字段可用于检索失败文档的字段?

【问题讨论】:

    标签: java elasticsearch


    【解决方案1】:

    在阅读了 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-03
      • 1970-01-01
      • 2017-05-17
      • 1970-01-01
      • 2019-07-17
      • 2021-10-31
      • 1970-01-01
      相关资源
      最近更新 更多