码迷,mamicode.com
首页 > 其他好文 > 详细

ElasticSearch批量更新文档

时间:2020-06-12 11:13:28      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:failed   索引   fail   class   bsp   uuid   try   cti   int   

 1     /**
 2      * 批量更新文档
 3      *
 4      * @param index     ES索引
 5      * @param documents 待提交的批量文档
 6      * @param uuidKey   文档中ID字段对应的key值
 7      */
 8     public BulkResponse updateDocumentsAsBatch(String index, List<Map<String, Object>> documents, String uuidKey) {
 9         BulkResponse response = null;
10         if (StringUtils.isBlank(index) || CollectionUtils.isEmpty(documents)) {
11             log.warn("Es index is blank or documents is empty.");
12             return response;
13         }
14 
15         try {
16             int size = documents.size();
17             BulkRequest bulkRequest = new BulkRequest();
18             for (int i = 0; i < size; i++) {
19                 Map<String, Object> document = documents.get(i);
20                 if (MapUtils.isEmpty(document) || !document.containsKey(uuidKey)) {
21                     continue;
22                 }
23                 bulkRequest.add(new UpdateRequest(index, document.get(uuidKey).toString()).doc(document));
24             }
25             response = client.bulk(bulkRequest, RequestOptions.DEFAULT);
26         } catch (Exception e) {
27             log.error("Update documents to es as batch failed!", e);
28         }
29         return response;
30     }

 

ElasticSearch批量更新文档

标签:failed   索引   fail   class   bsp   uuid   try   cti   int   

原文地址:https://www.cnblogs.com/seufelix/p/13097815.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!