每次保存的时候比如5000条数据,最后只报错了4100条,丢失了900
同样的数据再次同步,就可以成功
BulkRequestBuilder requestBuilder =getClient().prepareBulk()
insertMapList.forEach(mapData -> {
IndexRequestBuilder indexRequestBuilder = getClient().prepareIndex("demo", "demo", String.valueOf(mapData.getId()));
indexRequestBuilder.setSource(JsonUtils.toJSONWithDateString(mapData.getData()), XContentType.JSON);
requestBuilder.add(indexRequestBuilder);
});
BulkResponse result = requestBuilder.execute().actionGet(20000, TimeUnit.MILLISECONDS);
getClient().admin().indices().refresh(refreshRequest(“demo”)).actionGet();
返回的 BulkResponse 没有异常,也没有对外抛出异常同样的数据再次同步,就可以成功
1 个回复
陈水鱼 - 码农
赞同来自: