[英]How can we delete multiple documents at once in elastic search that belongs to different indexes?
I know we have delete_by_query
API that can do this job, but I'm looking for a solution using bulk API. I tried to follow https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html but it's only working when we delete documents from one index.我知道我们有delete_by_query
API 可以完成这项工作,但我正在寻找使用批量 API 的解决方案。我试图遵循https://www.elastic.co/guide/en/elasticsearch/reference/current/docs- bulk.html但它仅在我们从一个索引中删除文档时才起作用。 what about when we have more than one index that having comma(,) separated indexes like index1,index2
如果我们有多个以逗号 (,) 分隔的索引,例如index1,index2
,那该怎么办
You can build the request like that:您可以像这样构建请求:
PUT _bulk
{ "delete" : { "_index" : "products", "_id" : 1 } }
{ "delete" : { "_index" : "idx_movies", "_id" : 1 } }
Delete in different indice the same _id.在不同的索引中删除相同的_id。
The response will be (If find the doc, will be deleted else the response will be not found:响应将是(如果找到文档,将被删除,否则将找不到响应:
{
"took" : 6,
"errors" : false,
"items" : [
{
"delete" : {
"_index" : "products",
"_type" : "_doc",
"_id" : "1",
"_version" : 2,
"result" : "deleted",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 7,
"_primary_term" : 1,
"status" : 200
}
},
{
"delete" : {
"_index" : "idx_movies",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"result" : "not_found",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1012,
"_primary_term" : 2,
"status" : 404
}
}
]
}
You can use Bulk API with different index name as shown below:您可以使用具有不同索引名称的Bulk API ,如下所示:
POST _bulk
{ "delete" : { "_index" : "index1", "_id" : "1" } }
{ "delete" : { "_index" : "index1", "_id" : "2" } }
{ "delete" : { "_index" : "index2", "_id" : "3" } }
{ "delete" : { "_index" : "index3", "_id" : "4" } }
Similar you can achive using Elastic Java or any other language client as well.类似的,您也可以使用 Elastic Java 或任何其他语言客户端来实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.