开发者学堂课程【ElasticSearch 入门精讲:批量操作 bulk】学习笔记,与课程紧密连接,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/631/detail/9993
批量操作 bulk
ES JavaAPI 之批量操作 bulk
@Test
public void testBulklnsert() {
String deptDev= "("name"·"研发部", "deptNo" :20)";
String deptMarket = "("name""市场部", "deptNo" : 30)";
String deptOffice = "("name":"行政部", "deptNo" :40)";
client.prepareBulk()
.add(new IndexRequest(index, "dep", "1").source(deptDev))
.add(newIndexRequest(index,"dep", "2").source(deptMarket))
.add(newIndexRequest(index,"dep", "3").source(deptOffice))
.add(new DeleteRequest(index, type, "3")
·get();
}
@Test public void testBulkDealwith() { //步骤 //①准备需要进行批量操作的数据 //a)批量新增 IndexRequestBuilder indexRequestBuilder = client.preparelndex(INDEX, TYPE).setSource(JSON. toJSONString(new Product( name: "sqoop", author: "杰克逊“ IndexRequestBuilder indexRequestBuilder2 = client.preparelndex(INDEX, TYPE).setSource(JSON. toJSONString(new Product( name: "Flume", author. "杰克逊“ //b)批量删除 DeleteRequestBuilder deleteRequestBuilder = client.prepareDelete(INDEX, TYPE, id: "3"); //批处理实施 BulkResponse responses = client.prepareBulk() .add(indexRequestBuilder) .add(indexRequestBuilder2) .add(deleteRequestBuilder) .get(); |