After change the dynamic index setting which is number_of_replicas,ShardsAllocators would rebalance shard by BalancedShardsAllocator's Balancer,but i can't find which code to send the primary shard data to replica node.
Take a look at org.elasticsearch.indices.recovery.RecoverySource
.