ElasticSearch Delete API

Posted 一颗小蚕豆 期待发芽

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ElasticSearch Delete API相关的知识,希望对你有一定的参考价值。


一、根据查询结果删除(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的主要内容,如果未能解决你的问题,请参考以下文章

Elasticsearchindex [index] blocked by: [TOO_MANY_REQUESTS/12/index read-only / allow delete (api)](代

Elasticsearch 错误:cluster_block_exception [FORBIDDEN/12/index read-only / allow delete (api)], flood

Elasticsearch - cluster_block_exception [FORBIDDEN/12/index read-only / allow delete (api)]

ELK elasticsearch 因磁盘爆满导致无法 FORBIDDEN/12/index read-only / allow delete (api)

解决:ElasticSearch ClusterBlockException[blocked by: [FORBIDDEN/12/index read-only / allow delete (api

Elasticsearch Java Api--DeleteByQuery