1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| @Test public void batchCreateDocument() throws Exception { ElasticsearchClient esClient = ESUtil.getEsClient(); List<User> users = new ArrayList<>(); users.add(new User(1001, "letere", 18, "男")); users.add(new User(1002, "glucat", 22, "男")); users.add(new User(1003, "咕料", 30, "男")); users.add(new User(1004, "C酱", 28, "女")); List<BulkOperation> bulkOperations = new ArrayList<>(); for (User user : users) { bulkOperations.add(BulkOperation.of( b -> b.create( d -> d.id(user.getId().toString()).document(user) ) )); } BulkResponse response = esClient.bulk(i -> i.index("user").operations(bulkOperations)); System.out.println(response.items()); }
|