Search code examples
elasticsearchreindex

Transfer one shard or index between two Elasticsearch server


I know how copy an index in one server with Reindex API but now there are two servers (Elastic A and Elastic B) on two separated hosts like this:

Elastic A 
 |_ index a1
 |_ index a2

and

Elastic B 
 |_ index b1
 |_ index b2

I need to copy a1 to Elastic B and finally it's like this:

 Elastic B 
 |_ index b1
 |_ index b2
 |_ index a1

How can I do this? I'm waiting for any suggestion. Thanks, Mohammad.


Solution

  • In order to force one index onto a given host you can use shard allocation filtering

    PUT a1/_settings
    {
      "index.routing.allocation.require._host": "ElasticB"
    }
    

    However, just note that if you do this and your index a1's shards have replicas, the replicas won't be assigned to any host and your cluster will be yellow.