BulkRequest bulkRequest = new BulkRequest();
for (SearchPostIndexDTO searchPostIndexDTO : searchPostIndexList) {
IndexRequest indexRequest = new IndexRequest("index")
.id(String.valueOf(searchPostIndexDTO.getId()))
.source(JSON.toJSONString(searchPostIndexDTO), XContentType.JSON);
UpdateRequest updateRequest = new UpdateRequest("index", String.valueOf(searchPostIndexDTO.getId()))
.doc(JSON.toJSONString(searchPostIndexDTO), XContentType.JSON)
.upsert(indexRequest);
bulkRequest.add(updateRequest);
}
client.bulk(bulkRequest, RequestOptions.DEFAULT);
springBoot对es的批量upsert操作
于 2023-10-18 10:18:51 首次发布