Elasticsearch批量操作API用法介绍
2021-02-18 17:19
标签:ast 信息 row last cond listen UI code get Elasticsearch的Bulk API允许批量提交index和delete请求,有如下两种用法: Elasticsearch批量操作API用法介绍 标签:ast 信息 row last cond listen UI code get 原文地址:https://www.cnblogs.com/senlinyang/p/8336327.html用法1
BulkRequestBuilder requestBuilder = client.prepareBulk();
for(Person person : personList){
String obj = getIndexDataFromHotspotData(person);
if(obj != null){
requestBuilder.add(client.prepareIndex("test_index","test",String.valueOf(person.getId())).setRefresh(true).setSource(obj));
}
}
用法2
BulkProcessor bulkProcessor = BulkProcessor.builder(client, new BulkProcessor.Listener() {
@Override
public void beforeBulk(long l, BulkRequest bulkRequest) {
}
@Override
public void afterBulk(long l, BulkRequest bulkRequest, BulkResponse bulkResponse) {
}
@Override
public void afterBulk(long l, BulkRequest bulkRequest, Throwable throwable) {
}
}).setBulkActions(10000).setBulkSize(new ByteSizeValue(1, ByteSizeUnit.GB)).setFlushInterval(TimeValue.timeValueSeconds(5)).build();
for(Person person : personList){
String obj = getIndexDataFromHotspotData(person);
if(obj != null){
bulkProcessor.add(new IndexRequest("test_index","test",String.valueOf(person.getId())).source(obj));
}
}
上一篇:C# 构造器总结
文章标题:Elasticsearch批量操作API用法介绍
文章链接:http://soscw.com/index.php/essay/57150.html