ES中将多个索引合并到一个索引中

  • A+
所属分类:全文检索

在 Elasticsearch 中,可以使用 reindex API 将多个索引的内容移动到一个新的索引中。以下是一个将名为 source_index1source_index2 中的所有文档移动到名为 destination_index 中的示例:

POST _reindex
{
  "source": {
    "index": ["source_index1", "source_index2"]
  },
  "dest": {
    "index": "destination_index"
  }
}

这将从 source_index1source_index2 中获取所有文档,并将它们复制到新的 destination_index 中。如果目标索引 destination_index 不存在,它将被自动创建。

请注意,如果要在目标索引 destination_index 中保留源索引中的原始 _id 值,则可以使用以下示例中的 op_type 参数:

POST _reindex
{
  "source": {
    "index": ["source_index1", "source_index2"]
  },
  "dest": {
    "index": "destination_index",
    "op_type": "create"
  }
}

这将在目标索引中创建具有与源索引相同 _id 值的文档。如果在目标索引中已经存在具有相同 _id 的文档,则操作将失败。

您还可以在 source 参数中使用 query 参数来选择要移动的文档。有关更多选项和示例,请参阅 Elasticsearch 官方文档中的 reindex API。

ZPY

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: