zoukankan      html  css  js  c++  java
  • ElasticSearch批量更新文档

     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     }
  • 相关阅读:
    C语言I作业12—学期总结
    # 第一周作业
    C语言Ⅰ博客作业11
    C语言Ⅰ博客作业10
    C语言Ⅰ博客作业09
    C语言Ⅰ博客作业08
    C语言||作业01
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
  • 原文地址:https://www.cnblogs.com/seufelix/p/13097815.html
Copyright © 2011-2022 走看看