Java连接es,用bulk方法将数据库中数据同步到ES中:
主要用到了bulk.add()方法:
public void findByDistrictId() throws IOException {
List airList = airMapper.findByDistrictId(null,null,null,null);
BulkRequest bulkRequest = new BulkRequest();
for (Air air : airList) {
String jsonString = JSON.toJSONString(air);
IndexRequest indexRequest = new IndexRequest();
indexRequest.index("airinfo");
indexRequest.id(air.getId()+"");
indexRequest.source(jsonString, XContentType.JSON);
bulkRequest.add(indexRequest);
}
BulkResponse resp =ElasticSearchUtilTE.getClient().bulk(bulkRequest, RequestOptions.DEFAULT);
System.out.println(resp.status());
}



