# Copying indices on same cluster

**URL:** https://discuss.elastic.co/t/copying-indices-on-same-cluster/9549
**Category:** Elasticsearch
**Created:** [November 4, 2012, 6:09pm UTC](https://discuss.elastic.co/t/copying-indices-on-same-cluster/9549 "2012-11-04T18:09:45Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![krispyjala](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krispyjala/32/846_2.png) [@krispyjala](https://discuss.elastic.co/u/krispyjala)
#### Post date: [November 4, 2012, 6:09pm UTC](https://discuss.elastic.co/t/copying-indices-on-same-cluster/9549/1 "2012-11-04T18:09:45Z")

</div>

I was wondering how one would go about duplicating an index into another on  
the same cluster. I know you can probably write code to scan and reindex,  
but is that the only way? Is there some feature in ES that facilitates  
this kind of thing? I'm on 0.19.7.

-- KJ

--

---

<div class="post-metadata">

### Author: ![Rafal\_Kuc\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafal_kuc_3/32/799_2.png) [@Rafal\_Kuc\_3](https://discuss.elastic.co/u/Rafal_Kuc_3)
#### Post date: [November 4, 2012, 6:13pm UTC](https://discuss.elastic.co/t/copying-indices-on-same-cluster/9549/2 "2012-11-04T18:13:54Z")

</div>

Hello!

Haven't tried it myself, but you can try snapshot'ing and using the backup on another cluster - [http://www.elasticsearch.org/guide/reference/api/admin-indices-gateway-snapshot.html](http://www.elasticsearch.org/guide/reference/api/admin-indices-gateway-snapshot.html)

_--_

Regards,

Rafał Kuć

Sematext :: [http://sematext.com/](http://sematext.com/) _:: Solr - Lucene - Nutch - ElasticSearch_

I was wondering how one would go about duplicating an index into another on the same cluster. I know you can probably write code to scan and reindex, but is that the only way? Is there some feature in ES that facilitates this kind of thing? I'm on 0.19.7.

-- KJ

--

---

<div class="post-metadata">

### Author: ![krispyjala](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krispyjala/32/846_2.png) [@krispyjala](https://discuss.elastic.co/u/krispyjala)
#### Post date: [November 5, 2012, 3:43am UTC](https://discuss.elastic.co/t/copying-indices-on-same-cluster/9549/3 "2012-11-05T03:43:42Z")

</div>

Hi Rafal,  
Thanks for the suggestion, but I don't want to copy to another cluster.  
I want an identical index with a different name but with all the data  
intact on the SAME cluster.

-- KJ

On Sunday, November 4, 2012 10:14:06 AM UTC-8, Rafał Kuć wrote:

> Hello!
> 
> Haven't tried it myself, but you can try snapshot'ing and using the backup  
> on another cluster -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-gateway-snapshot.html)
> 
> \*--  
> Regards,  
> Rafał Kuć  
> Sematext :: _[http://sematext.com/](http://sematext.com/)_ :: Solr - Lucene - Nutch -  
> Elasticsearch
> 
> - 
> 
> I was wondering how one would go about duplicating an index into another  
> on the same cluster. I know you can probably write code to scan and  
> reindex, but is that the only way? Is there some feature in ES that  
> facilitates this kind of thing? I'm on 0.19.7.
> 
> ## -- KJ

--

---

<div class="post-metadata">

### Author: ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)
#### Post date: [November 5, 2012, 9:34am UTC](https://discuss.elastic.co/t/copying-indices-on-same-cluster/9549/4 "2012-11-05T09:34:37Z")

</div>

Hi KJ,

In that case, the following should work for a single node:

> <https://gist.github.com/radu-gheorghe/4016302>

If you have more nodes, you'd only have to "copy" metadata once for  
the whole cluster, then stop all nodes, copy the shards and start all  
the nodes again.

All this assumes you have and ES version of at least 0.19.8 and you  
have the default setting of gateway.local.auto\_import\_dangled: true

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Mon, Nov 5, 2012 at 5:43 AM, krispyjala [krispyjala@gmail.com](mailto:krispyjala@gmail.com) wrote:

> Hi Rafal,  
> Thanks for the suggestion, but I don't want to copy to another cluster. I want an identical index with a different name but with all the data intact on the SAME cluster.
> 
> -- KJ
> 
> On Sunday, November 4, 2012 10:14:06 AM UTC-8, Rafał Kuć wrote:
> 
> > Hello!
> > 
> > Haven't tried it myself, but you can try snapshot'ing and using the backup on another cluster - [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-gateway-snapshot.html)
> > 
> > --  
> > Regards,  
> > Rafał Kuć  
> > Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch - Elasticsearch
> > 
> > I was wondering how one would go about duplicating an index into another on the same cluster. I know you can probably write code to scan and reindex, but is that the only way? Is there some feature in ES that facilitates this kind of thing? I'm on 0.19.7.
> > 
> > ## -- KJ
> 
> --

--

---

<div class="post-metadata">

### Author: ![krispyjala](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krispyjala/32/846_2.png) [@krispyjala](https://discuss.elastic.co/u/krispyjala)
#### Post date: [November 5, 2012, 1:55pm UTC](https://discuss.elastic.co/t/copying-indices-on-same-cluster/9549/5 "2012-11-05T13:55:52Z")

</div>

Wow, great script, Radu. As I said though, I am on 0.19.7. Are there any  
features I need in 0.19.8 that will prevent me from using this script on  
0.19.7?

Thanks,  
KJ

On Mon, Nov 5, 2012 at 1:34 AM, Radu Gheorghe [radu.gheorghe@sematext.com](mailto:radu.gheorghe@sematext.com)wrote:

> Hi KJ,
> 
> In that case, the following should work for a single node:  
> [copy one Elasticesarch index to another · GitHub](https://gist.github.com/4016302)
> 
> If you have more nodes, you'd only have to "copy" metadata once for  
> the whole cluster, then stop all nodes, copy the shards and start all  
> the nodes again.
> 
> All this assumes you have and ES version of at least 0.19.8 and you  
> have the default setting of gateway.local.auto\_import\_dangled: true
> 
> ## Best regards, Radu
> 
> [http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene
> 
> On Mon, Nov 5, 2012 at 5:43 AM, krispyjala [krispyjala@gmail.com](mailto:krispyjala@gmail.com) wrote:
> 
> > Hi Rafal,  
> > Thanks for the suggestion, but I don't want to copy to another  
> > cluster. I want an identical index with a different name but with all the  
> > data intact on the SAME cluster.
> > 
> > -- KJ
> > 
> > On Sunday, November 4, 2012 10:14:06 AM UTC-8, Rafał Kuć wrote:
> > 
> > > Hello!
> > > 
> > > Haven't tried it myself, but you can try snapshot'ing and using the  
> > > backup on another cluster -  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-gateway-snapshot.html)
> > > 
> > > --  
> > > Regards,  
> > > Rafał Kuć  
> > > Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch -  
> > > Elasticsearch
> > > 
> > > I was wondering how one would go about duplicating an index into  
> > > another on the same cluster. I know you can probably write code to scan  
> > > and reindex, but is that the only way? Is there some feature in ES that  
> > > facilitates this kind of thing? I'm on 0.19.7.
> > > 
> > > ## -- KJ
> > 
> > --
> 
> --

--

---

<div class="post-metadata">

### Author: ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)
#### Post date: [November 5, 2012, 2:34pm UTC](https://discuss.elastic.co/t/copying-indices-on-same-cluster/9549/6 "2012-11-05T14:34:30Z")

</div>

Hello,

Sorry, I got lost in my own thoughts :(. Although I didn't test it on  
0.19.7, it should work.

My initial approach would have been to copy the data directory of the  
"old" index to a "new" directory and restart Elasticsearch. Then,  
Elasticsearch would have seen the "new" directory as a dangled index  
and try to import it. And you would need 0.19.8 to import those  
dangled indices.

But I couldn't actually copy an index this way, so that's why I went  
on the path of simply reposting the same metadata in the new index,  
and copying the shards themselves when ES is offline. That seems to  
work, and it has nothing to do with dangled indices. So it should work  
for 0.19.7 as well.

I would suggest to try this option in a test environment and post here  
if you have any trouble.

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Mon, Nov 5, 2012 at 3:55 PM, Kris Jirapinyo [krispyjala@gmail.com](mailto:krispyjala@gmail.com) wrote:

> Wow, great script, Radu. As I said though, I am on 0.19.7. Are there any  
> features I need in 0.19.8 that will prevent me from using this script on  
> 0.19.7?
> 
> Thanks,  
> KJ
> 
> On Mon, Nov 5, 2012 at 1:34 AM, Radu Gheorghe [radu.gheorghe@sematext.com](mailto:radu.gheorghe@sematext.com)  
> wrote:
> 
> > Hi KJ,
> > 
> > In that case, the following should work for a single node:  
> > [copy one Elasticesarch index to another · GitHub](https://gist.github.com/4016302)
> > 
> > If you have more nodes, you'd only have to "copy" metadata once for  
> > the whole cluster, then stop all nodes, copy the shards and start all  
> > the nodes again.
> > 
> > All this assumes you have and ES version of at least 0.19.8 and you  
> > have the default setting of gateway.local.auto\_import\_dangled: true
> > 
> > ## Best regards, Radu
> > 
> > [http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene
> > 
> > On Mon, Nov 5, 2012 at 5:43 AM, krispyjala [krispyjala@gmail.com](mailto:krispyjala@gmail.com) wrote:
> > 
> > > Hi Rafal,  
> > > Thanks for the suggestion, but I don't want to copy to another  
> > > cluster. I want an identical index with a different name but with all the  
> > > data intact on the SAME cluster.
> > > 
> > > -- KJ
> > > 
> > > On Sunday, November 4, 2012 10:14:06 AM UTC-8, Rafał Kuć wrote:
> > > 
> > > > Hello!
> > > > 
> > > > Haven't tried it myself, but you can try snapshot'ing and using the  
> > > > backup on another cluster -  
> > > > [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-gateway-snapshot.html)
> > > > 
> > > > --  
> > > > Regards,  
> > > > Rafał Kuć  
> > > > Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch -  
> > > > Elasticsearch
> > > > 
> > > > I was wondering how one would go about duplicating an index into  
> > > > another on the same cluster. I know you can probably write code to scan and  
> > > > reindex, but is that the only way? Is there some feature in ES that  
> > > > facilitates this kind of thing? I'm on 0.19.7.
> > > > 
> > > > ## -- KJ
> > > 
> > > --
> > 
> > --
> 
> --

--

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 3:06am UTC](https://discuss.elastic.co/t/copying-indices-on-same-cluster/9549/7 "2017-07-06T03:06:11Z")

</div>


