1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| @Test public void testBulk() throws IOException { IndexRequest indexRequest1 = new IndexRequest("buubiu", "user", "12"); User user1 = new User("1","刘能1", 22, new Date(), "男", "这是好人"); indexRequest1.source(JSONObject.toJSONStringWithDateFormat(user1,"yyyy-MM-dd"), XContentType.JSON); IndexRequest indexRequest2 = new IndexRequest("buubiu", "user", "13"); User user2 = new User("2","刘能2", 24, new Date(), "男", "这是好人"); indexRequest2.source(JSONObject.toJSONStringWithDateFormat(user2,"yyyy-MM-dd"), XContentType.JSON); UpdateRequest updateRequest = new UpdateRequest("buubiu", "user", "12"); User user = new User().setName("中国厉害"); updateRequest.doc(JSONObject.toJSONString(user), XContentType.JSON); DeleteRequest deleteRequest = new DeleteRequest("buubiu", "user", "13");
BulkResponse bulkItemResponses = transportClient.prepareBulk().add(indexRequest1) .add(indexRequest2).add(updateRequest).add(deleteRequest).get(); BulkItemResponse[] items = bulkItemResponses.getItems(); for (BulkItemResponse item : items) { System.out.println("item = " + item.status()); }
}
|