1. 程式人生 > >ElasticSearch(五) Delete API

ElasticSearch(五) Delete API

elastic .so failure ast program ted listing 文檔 new


一、根據查詢結果刪除(Delete By Query API)

BulkByScrollResponse response =
DeleteByQueryAction.INSTANCE.newRequestBuilder(client) // transport client
.filter(QueryBuilders.matchQuery("gender", "male")) //查詢條件
.source("persons") //索引名稱
.get();

long deleted = response.getDeleted();    //已刪除的文檔數量
二、對查詢結果異步刪除

DeleteByQueryAction.INSTANCE.newRequestBuilder(client)
.filter(QueryBuilders.matchQuery("gender", "male"))
.source("persons")
.execute(new ActionListener<BulkByScrollResponse>() {
@Override
public void onResponse(BulkByScrollResponse response) {
long deleted = response.getDeleted();
}
@Override
public void onFailure(Exception e) {
// Handle the exception
}
});

ElasticSearch(五) Delete API