【问题标题】:How to catch bulk response with bulk processor?(Java High level rest client)如何使用批量处理器捕获批量响应?(Java 高级休息客户端)
【发布时间】:2020-02-26 06:10:25
【问题描述】:

我是 Elasticsearch Java API 的新手。我知道批量操作有两种方式:

  1. 构造一个批量请求,使用客户端对象。

  2. 构造一个批量处理器,向它添加请求。

我模拟了一大堆mock数据(约1M条),并用Java高级rest客户端将它们索引到Elasticsearch(5.6.3)中。

但是,如果我使用批量请求来索引大批量,

java.lang.OutOfMemoryError: nullexception

当我使用 client.bulk() 方法时发生。

然后我尝试使用批量处理器,它可以工作。 代码如下:

RestHighLevelClient client = initESclient();
BulkProcessor bulkProcessor = initES(client);

logger.info("Use bulk request to load data:");
logger.info("start to generate random data...");
String bossMockIndex = customSetting.getMockIndex();
String soapMockType = customSetting.getSoapType();
Long start = System.currentTimeMillis();
Integer batch = customSetting.getMockBatch();
logger.info("Batch:"+batch);
List<IndexRequest> indexRequesList = bossMockDataService.indexRequestGenerator(batch, bossMockIndex, soapMockType);
Long endCreateData = System.currentTimeMillis();
logger.info("Consumption for creating "+batch+" pieces of mock data:"+(endCreateData-start)/1000.0d+"s");

for (IndexRequest indexRequest : indexRequesList) {
    bulkProcessor.add(indexRequest);
}

我想知道如何使用BulkProcessor 获得这个批量响应,就像我使用BulkRequest 时一样。我需要更新这批数据中的一些数据。

【问题讨论】:

    标签: java elasticsearch


    【解决方案1】:
    BulkResponse bulkResponse = bulkProcessor.execute().actionGet();
    

    【讨论】:

      猜你喜欢
      • 2017-09-06
      • 2014-10-07
      • 2022-01-20
      • 2019-05-26
      • 1970-01-01
      • 2016-03-30
      • 2016-03-21
      • 2011-03-31
      • 1970-01-01
      相关资源
      最近更新 更多