elasticsearch java插入索引批量操作
1.单条所以插入
//第一个参数:索引名;第二个参数:索引类型;第三个参数:索引ID(相同的id时修改数据,默认为随机字符串)
IndexResponse indexResponse = client.prepareIndex("twitter", "json","1").setSource(json).get();
2.批量插入
BulkRequestBuilder bulkRequest = client.prepareBulk();
IndexRequest request = client.prepareIndex("twitter", "json","1").setSource(json).request();
IndexRequest request2 = client.prepareIndex("twitter", "json","2").setSource(json2).request();
bulkRequest.add(request);
bulkRequest.add(request2);
bulkRequest.execute().actionGet();