--- title: "Easysearch 迁移数据之 Reindex From Remote" date: 2025-04-16 lastmod: 2025-04-16 description: "本文介绍了 Easysearch 集群如何从远程集群 Reindex 数据。" tags: ["Easysearch"] summary: "在之前的博客《 从 Elastic 迁移到 Easysearch 指引》中介绍过如何把索引从 Elasticsearch 迁移到 Easysearch。有时候想临时从 Elasticsearch 迁移点儿数据做测试,数据量不大,也可尝试使用 Reindex From Remote 的方法。 测试环境介绍 # 本次主要测试从远程集群索引数据,reindex 还有很多其他使用方式,详情请参考 官方文档。 Easysearch 版本:1.10.0,监听 localhost:9200 Elasticsearch 版本:6.8.23,监听 localhost:9201 INFINI Console 版本:1.25.1(运行 reindex 命令用) Reindex API # Reindex 可以从本地或远程集群将源索引数据写入本地目标索引。使用简单,有以下注意点: 源索引启用 _source ,这个默认都是启用的 在调用 _reindex 之前,应该先创建、配置目标索引 如果源索引在远程集群,必须在 easysearch.yml 中配置 reindex.remote.whitelist 设置 使用 POST 调用 测试过程 # 我们先不设置白名单,直接从远程集群 reindex 看看会怎样。 报错提示 localhost:9201 不在 reindex.remote.whitelist 中。 正常操作步骤 编辑 Easysearch 配置文件 easysearch." --- 在之前的博客《[从 Elastic 迁移到 Easysearch 指引](https://infinilabs.cn/blog/2024/migrate-from-elastic-to-easysearch/)》中介绍过如何把索引从 Elasticsearch 迁移到 Easysearch。有时候想临时从 Elasticsearch 迁移点儿数据做测试,数据量不大,也可尝试使用 Reindex From Remote 的方法。 ## 测试环境介绍 本次主要测试从远程集群索引数据,reindex 还有很多其他使用方式,详情请参考[官方文档](https://docs.infinilabs.com/easysearch/main/docs/references/management/reindex-data/)。 - Easysearch 版本:1.10.0,监听 localhost:9200 - Elasticsearch 版本:6.8.23,监听 localhost:9201 - INFINI Console 版本:1.25.1(运行 reindex 命令用) ## Reindex API Reindex 可以从本地或远程集群将源索引数据写入本地目标索引。使用简单,有以下注意点: - 源索引启用 \_source ,这个默认都是启用的 - 在调用 \_reindex 之前,应该先创建、配置目标索引 - 如果源索引在远程集群,必须在 easysearch.yml 中配置 reindex.remote.whitelist 设置 - 使用 POST 调用 ## 测试过程 我们先不设置白名单,直接从远程集群 reindex 看看会怎样。 {{% load-img "/img/blog/2025/easysearch-reindex-from-remote/1.png" "" %}} 报错提示 localhost:9201 不在 reindex.remote.whitelist 中。 **正常操作步骤** 1. 编辑 Easysearch 配置文件 easysearch.yml,添加白名单,重启生效。 ```plain reindex.remote.whitelist: [localhost:9201] ``` 2. 建立目标索引,指定 setting 和 mapping reindex 不会复制源索引的 setting 和 mapping,需要提前创建目标索引,否则会使用默认设置。 3. 执行 reindex 命令 {{% load-img "/img/blog/2025/easysearch-reindex-from-remote/2.png" "" %}} 执行成功。需要注意的是,如果数据量比较大,reindex 命令会超时,这个没关系,任务会继续在后台执行。也可以在执行 reindex 的时候添加参数 wait_for_completion=false 不等待执行完成,直接返回任务 id。 ```plain POST _reindex?wait_for_completion=false ``` {{% load-img "/img/blog/2025/easysearch-reindex-from-remote/3.png" "" %}} 针对有认证的集群,reindex 可以指定以下选项: {{% load-img "/img/blog/2025/easysearch-reindex-from-remote/4.png" "" %}} ## 总结 针对临时数据量不大的场景可尝试使用 reindex 迁移数据。如果数据量大了,reindex 迁移速度不是很高效,而且如果中途出现错误迁移中断了,需要重新 reindex 不方便,建议使用 [INFINI Console 进行数据迁移](https://docs.infinilabs.com/console/main/zh/docs/reference/migration/migration/)。 有任何问题,欢迎加我微信沟通。 {{% load-img "/img/blog/banner/about_yangf.png" "" %}}