简体   繁体   English

elasticsearch中如何一次性删除多个属于不同索引的文档?

[英]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.

相关问题 弹性搜索 - 使用具有不同数据结构的文档的多个索引进行搜索 - Elastic Search - Search using multiple indexes with documents that have different data structures 如何在弹性搜索中基于多个地理点搜索文档? - How can i search documents based on multiple geopoints in elastic search? 弹性搜索delete_by_query如何工作? 当我们在删除文档时插入新数据并检索相同内容时会发生什么? - How Elastic Search delete_by_query work ? What happens when we insert new data and retrieve the same while deleting documents? 我可以在Spring Bean配置中为多个弹性搜索索引使用多个弹性搜索主机 - Can I use multiple elastic search hosts in Spring Bean configuration for multiple elastic search indexes 输入弹性搜索,可以包含不同类型的文档 - Type in elastic search, that can be contains documents of different types 使用 Elastic Search,我如何将包含数组的文档索引到多个文档中,每个数组项一个? - With Elastic Search, how can I index a document containing an array into multiple documents, one per array item? 如何仅在“内存中”使用弹性搜索索引? - How can I use elastic search indexes exclusively "in-memory"? 如何找到与 Elastic 搜索别名关联的所有索引? - how can I find all of the indexes associated with an Elastic search alias? 如何在弹性搜索中创建具有相同ID的不同文档 - How to create different documents in elastic search but same ID 使用来自不同索引的数据进行弹性搜索计算 - Elastic search calculation with data from different indexes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM