我需要使用Elasticsearch的bulkprocessor将一些批量数据插入弹性搜索中。 这是我从elastic.co获得的。
import org.elasticsearch.action.bulk.BulkProcessor;
BulkProcessor bulkProcessor = BulkProcessor.builder(
client,
new BulkProcessor.Listener() {
@Override
public void beforeBulk(long executionId,
BulkRequest request) { }
@Override
public void afterBulk(long executionId,
BulkRequest request,
BulkResponse response) { }
@Override
public void afterBulk(long executionId,
BulkRequest request,
Throwable failure) { }
})
.setBulkActions(10000)
.setBulkSize(new ByteSizeValue(1, ByteSizeUnit.GB))
.setFlushInterval(TimeValue.timeValueSeconds(5))
.setConcurrentRequests(1)
.build();
bulkProcessor.add(new IndexRequest("twitter", "tweet", "1").source("helloworld"));
bulkProcessor.add(new DeleteRequest("twitter", "tweet", "2"));
我是否需要为所有批量插入过程调用BulkProcessor.builder?这是使用批量处理器的正确方法吗?