我正在尝试使用BulkProcessor
执行批量删除请求,初始化代码如下:
BulkProcessor bulkProcessor = BulkProcessor.builder(client, new BulkProcessor.Listener() {
@Override
public void beforeBulk(long executionId, BulkRequest request) {
log.warn("executionId:" + executionId + " bulk start => numberOfActions:" + request.numberOfActions() + " size:" + request.estimatedSizeInBytes());
}
@Override
public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
log.warn("executionId:" + executionId + " bulk end => tookInMillis:" + response.getTookInMillis());
log.warn("executionId:" + executionId + " bulk end => response:" + JSON.toJSONString(response));
}
@Override
public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
log.warn("executionId:" + executionId + " bulk executed occur error:", failure);
}
}).setBulkActions(500).setBulkSize(new ByteSizeValue(14, ByteSizeUnit.MB)).setConcurrentRequests(1).build();
//search ids to delete
List<String> ids = searchByCondition(index,type,start,end); //ids.size() = 500
//call bulk
for(String id : ids){
DeleteRequest deleteRequest = new DeleteRequest(index, type, id);
bulkProcessor.add(deleteRequest);
}
在请求后,es中没有记录被删除。而且我得到的处理结果日志如下:
{
"context":{
"empty":true
},
"contextEmpty":true,
"headers":[
],
"items":[
{
"failed":false,
"id":"14720103",
"index":"my_index",
"itemId":483,
"opType":"delete",
"response":{
"context":{
"$ref":"$.context"
},
"contextEmpty":true,
"found":false,
"headers":[
],
"id":"14720103",
"index":"my_index",
"shardInfo":{
"failed":0,
"failures":[
],
"successful":1,
"total":1
},
"type":"my_type",
"version":1
},
"type":"my_type",
"version":1
},
{
"failed":false,
"id":"14720827",
"index":"my_index",
"itemId":484,
"opType":"delete",
"response":{
"context":{
"$ref":"$.context"
},
"contextEmpty":true,
"found":false,
"headers":[
],
"id":"14720827",
"index":"my_index",
"shardInfo":{
"failed":0,
"failures":[
],
"successful":1,
"total":1
},
"type":"my_type",
"version":1
},
"type":"my_type",
"version":1
},
{
"failed":false,
"id":"14720898",
"index":"my_index",
"itemId":499,
"opType":"delete",
"response":{
"context":{
"$ref":"$.context"
},
"contextEmpty":true,
"found":false,
"headers":[
],
"id":"14720898",
"index":"my_index",
"shardInfo":{
"failed":0,
"failures":[
],
"successful":1,
"total":1
},
"type":"my_type",
"version":1
},
"type":"my_type",
"version":1
}
],
"took":{
"days":0,
"daysFrac":5.358796296296296E-6,
"hours":0,
"hoursFrac":1.286111111111111E-4,
"micros":463000,
"microsFrac":463000.0,
"millis":463,
"millisFrac":463.0,
"minutes":0,
"minutesFrac":0.007716666666666667,
"nanos":463000000,
"seconds":0,
"secondsFrac":0.463
},
"tookInMillis":463
}
感谢您的帮助,谢谢!