すべてのプロダクト
Search
ドキュメントセンター

Elasticsearch:Reindex API を使用したデータ移行

最終更新日:Jun 23, 2026

Reindex API は、ソースインデックスから送信先インデックスにドキュメントをコピーします。すべてのドキュメントをコピーすることも、特定のクエリに一致するドキュメントのみをコピーすることもできます。このプロセスは、同じクラスター内または異なるクラスター間で実行できます。このトピックでは、Reindex API を使用して、あるクラスターから別のクラスターにデータを移行する方法について説明します。

制限事項

  • 両方のクラスターが同じリージョンおよびアベイラビリティゾーンにある必要があります。

  • 管理およびデプロイモード:v2 クラスターから v3 クラスターへ、2 つの v2 クラスター間、または 2 つの v3 クラスター間でデータを移行できます。

    クラスターには、クラウドネイティブ新管理 (v3) と基本管理 (v2) の 2 つの管理およびデプロイモードがあります。クラスターの管理およびデプロイモードは、コンソール上の情報ページで確認できます。

  • クラスターバージョン:データ移行は、同じメジャーバージョンのクラスター間でサポートされます (例:下位のマイナーバージョンから上位のマイナーバージョンへ)。7.7.1 から 8.15.1 のように、メジャーバージョンをまたいだデータ移行は推奨されません。

前提条件

この例では、Reindex API を使用して ES_2 から ES_1 にデータを移行します。開始する前に、次の準備を完了してください。

テストデータの準備

  • ES_2 で、インデックスを作成し、テストデータを挿入します:

    PUT /product_info
    {
      "settings": {
        "number_of_shards": 5,
        "number_of_replicas": 1
      },
      "mappings": {
          "properties": {
            "productName": {
              "type": "text",
              "analyzer": "ik_smart"
            },
            "annual_rate":{
              "type":"keyword"
            },
            "describe": {
              "type": "text",
              "analyzer": "ik_smart"
            }
        }
      }
    }

    このコマンドは、product_info という名前のインデックスを作成します。このインデックスには productNameannual_ratedescribe フィールドが含まれます。リクエストが成功すると、次の結果が返されます。

    {
      "acknowledged" : true,
      "shards_acknowledged" : true,
      "index" : "product_info"
    }

    6 つのテストドキュメントを挿入します:

    POST /product_info/_bulk
    {"index":{}}
    {"productName":"Financial Product A","annual_rate":"3.2200%","describe":"A 180-day fixed-term product with a minimum investment of 20,000. Stable returns with optional message notifications."}
    {"index":{}}
    {"productName":"Financial Product B","annual_rate":"3.1100%","describe":"A 90-day regular investment product with a minimum investment of 10,000. Daily profit notifications are sent."}
    {"index":{}}
    {"productName":"Financial Product C","annual_rate":"3.3500%","describe":"A 270-day regular investment product with a minimum investment of 40,000. Daily profit notifications are sent."}
    {"index":{}}
    {"productName":"Financial Product D","annual_rate":"3.1200%","describe":"A 90-day regular investment product with a minimum investment of 12,000. Daily profit notifications are sent."}
    {"index":{}}
    {"productName":"Financial Product E","annual_rate":"3.0100%","describe":"A recommended 30-day regular investment product with a minimum investment of 8,000. Daily profit notifications are sent."}
    {"index":{}}
    {"productName":"Financial Product F","annual_rate":"2.7500%","describe":"A popular 3-day short-term product with no fees and a minimum investment of 500. Profit notifications are sent via SMS."}
  • ES_1 で、ES_2 から移行されたデータを格納するためのインデックスを作成します:

    PUT dest
    {
      "settings": {
        "number_of_shards": 5,
        "number_of_replicas": 1
      }
    }

NLB と PrivateLink によるプライベート接続

クラスターのセキュリティを強化するため、同じ VPC または異なる VPC 内のクラスターはネットワーク的に隔離されています。NLB と PrivateLink を使用して、クラスター間にプライベート接続 (VPC 接続) を確立する必要があります。

次の図に示すように、2 つの ES クラスターは同じ VPC にデプロイされています。ユーザーの VPC にエンドポイントサービスが作成されます。次に、ES_1 でプライベート接続が設定され、エンドポイントが取得されます。最後に、エンドポイントがエンドポイントサービスに関連付けられ、2 つのクラスター間にプライベート接続が確立されます。

エンドポイントサービスは、他の VPC がエンドポイントを作成することによってプライベートに接続できるサービスです。関連するサービスリソースは手動で作成する必要があります。
エンドポイントは、エンドポイントサービスに関連付けられ、外部サービスにアクセスするためのプライベートネットワーク接続を提供します。Alibaba Cloud Elasticsearch (ES) インスタンスのプライベート接続を設定すると、ES クラスターが存在するネットワーク環境にエンドポイントが自動的に作成されます。

詳細な設定手順については、「NLB と PrivateLink を使用した Alibaba Cloud ES クラスター間のプライベート接続の確立」をご参照ください。ステップ 1、ステップ 2、ステップ 3 を完了する必要があります。

ES_1 インスタンスの [セキュリティ設定] ページで、[クラスターネットワーク設定] セクションの [インスタンスのプライベート接続を設定] の右側にある [変更] をクリックします。[インスタンスのプライベート接続を設定] パネルで、エンドポイント ID、エンドポイントサービス ID、および接続ステータスを確認できます。エンドポイントの接続ステータスが [接続済み] になると、ES_1 と ES_2 クラスターはプライベート IP アドレスを介して通信できるようになります。

Reindex API ホワイトリストの設定

クラスター間の安全なデータ移行を保証するため、ES_2 クラスターのプライベート接続アドレスとポートを ES_1 の Reindex API ホワイトリストに追加する必要があります。

  1. ES_1 の セキュリティ ページに移動し、プライベート接続の設定 の横にある 編集 をクリックします。プライベート接続の設定 サイドパネルで、対象の エンドポイント ID をクリックします。

    新しい接続を追加するには、[インスタンスのプライベート接続を設定] サイドパネルの下部にある [+ プライベート接続の追加] をクリックします。

  2. VPC コンソールで、エンドポイント接続 タブに移動し、エンドポイント ID の横にある 展开符 アイコンをクリックして、対応するドメイン名を表示します。

    重要

    Reindex API ホワイトリストに追加する前に、ドメイン名からアベイラビリティゾーン識別子を削除する必要があります。

    例えば、完全なドメイン名が「ep-bp1****************-cn-hangzhou-i.epsrv-bp1****************.cn-hangzhou.privatelink.aliyuncs.com」の場合、アベイラビリティゾーン識別子「-cn-hangzhou-i」を削除して、最終的なドメイン名「ep-bp1bp1****************.epsrv-bp1****************.cn-hangzhou.privatelink.aliyuncs.com」を取得します。

  3. ES_1 の YML ファイルで、Reindex API ホワイトリストを設定します。ホワイトリストのエントリは、エンドポイントのドメイン名とポートでなければなりません。

    reindex:
      remote:
        whitelist: >-
          ep-bp1bp1****************.epsrv-bp1****************.cn-hangzhou.privatelink.aliyuncs.com:9200

    [ES クラスター設定] ページで、[YML 設定] の右側にある [設定の変更] をクリックします。パネル内の [その他の設定] YAML エディターに、前述のホワイトリスト設定を追加します。

Reindex API の呼び出し

  1. ES_1 の Kibana コンソールにログインします。

  2. [Dev Tools] > [コンソール]で、Reindex API を呼び出してデータを移行します。

    POST _reindex
    {
      "source": {
        "remote": {
          "host": "http://ep-bp1bp1****************.epsrv-bp1****************.cn-hangzhou.privatelink.aliyuncs.com:9200",
          "username": "elastic",
          "password": "xxx-xxxx123!"
        },
        "index": "product_info",
        "query": {
          "match": {
            "productName": "Financial Product"
          }
        }
      },
      "dest": {
        "index": "dest"
      }
    }

    カテゴリ

    パラメーター

    説明

    source

    remote

    リモートクラスター。この例では ES_2 です。

    host

    ES_2 クラスターのアクセスアドレス。以下を含みます:

    • プロトコル。これはクラスターの 基本情報 ページで確認できます。

      重要

      セキュリティのため、クラスターに接続する際にパスワードがプレーンテキストで送信されるのを防ぐには、HTTPS プロトコルを使用します。HTTPS プロトコルを有効にするには、「HTTPS プロトコル」をご参照ください。

    • ドメイン名:ES_2 クラスターのプライベート接続アドレス。これは Reindex ホワイトリストで設定したドメイン名と同じでなければなりません。

    • ポート:9200 に固定されています。

    username

    クラスターのデフォルトのユーザー名は `elastic` です。

    password

    指定されたユーザーのパスワード。

    パスワードはクラスター作成時に設定しました。忘れた場合は、パスワードをリセットできます。

    index

    リモートクラスターのソースインデックス。

    query

    移行するドキュメントを指定するクエリ。

    この例では、`productName` フィールドに「Financial Product」が含まれるドキュメントが、ES_2 クラスターのインデックスから ES_1 クラスターに移行されます。

    dest

    index

    移行されたデータの送信先となるターゲットクラスター内のインデックス。

    リクエストが成功すると、次の結果が返されます:

    {
      "took": 211,
      "timed_out": false,
      "total": 6,
      "updated": 6,
      "created": 0,
      "deleted": 0,
      "batches": 1,
      "version_conflicts": 0,
      "noops": 0,
      "retries": {
        "bulk": 0,
        "search": 0
      },
      "throttled_millis": 0,
      "requests_per_second": -1,
      "throttled_until_millis": 0,
      "failures": []
    }
  3. _search API を呼び出して移行結果を表示します。

    GET dest/_search

    期待される結果:

    {
      "took": 6,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": {
          "value": 6,
          "relation": "eq"
        },
        "max_score": 1,
        "hits": [
          {
            "_index": "dest",
            "_id": "n9kyqpcBCRuDZhswJCpH",
            "_score": 1,
            "_source": {
              "productName": "Financial Product D",
              "annual_rate": "3.1200%",
              "describe": "A 90-day regular investment product with a minimum investment of 12,000. Daily profit notifications are sent."
            }
          },
          {
            "_index": "dest",
            "_id": "nNkyqpcBCRuDZhswJCpG",
            "_score": 1,
            "_source": {
              "productName": "Financial Product A",
              "annual_rate": "3.2200%",
              "describe": "A 180-day fixed-term product with a minimum investment of 20,000. Stable returns with optional message notifications."
            }
          },
          {
            "_index": "dest",
            "_id": "ndkyqpcBCRuDZhswJCpG",
            "_score": 1,
            "_source": {
              "productName": "Financial Product B",
              "annual_rate": "3.1100%",
              "describe": "A 90-day regular investment product with a minimum investment of 10,000. Daily profit notifications are sent."
            }
          },
          {
            "_index": "dest",
            "_id": "ntkyqpcBCRuDZhswJCpH",
            "_score": 1,
            "_source": {
              "productName": "Financial Product C",
              "annual_rate": "3.3500%",
              "describe": "A 270-day regular investment product with a minimum investment of 40,000. Daily profit notifications are sent."
            }
          },
          {
            "_index": "dest",
            "_id": "oNkyqpcBCRuDZhswJCpH",
            "_score": 1,
            "_source": {
              "productName": "Financial Product E",
              "annual_rate": "3.0100%",
              "describe": "A recommended 30-day regular investment product with a minimum investment of 8,000. Daily profit notifications are sent."
            }
          },
          {
            "_index": "dest",
            "_id": "odkyqpcBCRuDZhswJCpH",
            "_score": 1,
            "_source": {
              "productName": "Financial Product F",
              "annual_rate": "2.7500%",
              "describe": "A popular 3-day short-term product with no fees and a minimum investment of 500. Profit notifications are sent via SMS."
            }
          }
        ]
      }
    }

よくある質問

Q:ドキュメントサイズに基づいて Reindex API のバッチサイズとタイムアウトを調整するにはどうすればよいですか?

  • バッチサイズの調整

    インデックス再作成操作のデフォルトのバッチサイズは 1,000 ドキュメントです。インデックスに大きなドキュメントが含まれている場合は、この値を小さくしてタイムアウトを防ぐことができます。

    次の例では、size10 に設定され、バッチごとに 10 ドキュメントを処理します。

    POST _reindex
    {
      "source": {
        "remote": {
          "host": "http://otherhost:9200"
        },
        "index": "source",
        "size": 10,
        "query": {
          "match": {
            "test": "data"
          }
        }
      },
      "dest": {
        "index": "dest"
      }
    }
  • タイムアウトの調整

    `socket_timeout` パラメーターは、ソケットの読み取りタイムアウトを設定します (デフォルトは 30 秒)。`connect_timeout` パラメーターは、クラスターの接続タイムアウトを設定します (デフォルトは 1 秒)。

    次の例では、ソケットの読み取りタイムアウトが 1 分に、接続タイムアウトが 10 秒に設定されています。

    POST _reindex
    {
      "source": {
        "remote": {
          "host": "http://otherhost:9200",
          "socket_timeout": "1m",
          "connect_timeout": "10s"
        },
        "index": "source",
        "query": {
          "match": {
            "test": "data"
          }
        }
      },
      "dest": {
        "index": "dest"
      }
    }