# How to take data from old server and \*merge\* it with data on new server

**URL:** https://discuss.elastic.co/t/how-to-take-data-from-old-server-and-merge-it-with-data-on-new-server/27658
**Category:** Elasticsearch
**Created:** [August 19, 2015, 9:42am UTC](https://discuss.elastic.co/t/how-to-take-data-from-old-server-and-merge-it-with-data-on-new-server/27658 "2015-08-19T09:42:02Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![John\_Thornborrow](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@John\_Thornborrow](https://discuss.elastic.co/u/John_Thornborrow)
#### Post date: [August 19, 2015, 9:42am UTC](https://discuss.elastic.co/t/how-to-take-data-from-old-server-and-merge-it-with-data-on-new-server/27658/1 "2015-08-19T09:42:02Z")

</div>

Hi,

We've recently upgraded our hardware, and have now got a replacement ES cluster.

I want to restore the indices on our old cluster into/onto the new cluster without losing what is currently on the new cluster. I.e. I want to merge the data.

Which is the best way to achieve this? I've read the snapshot/restore docs and it appears that the restore doesn't have a non-destructive/merge feature, only a "drop and recreate" (to borrow an antiquated phrase) method.

This is all on Windows, which I'm sure I'll be told makes things even more difficult.

Thanks for any help,  
John

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [August 19, 2015, 9:48am UTC](https://discuss.elastic.co/t/how-to-take-data-from-old-server-and-merge-it-with-data-on-new-server/27658/2 "2015-08-19T09:48:07Z")

</div>

You could write a small program using one of the [official Elasticsearch clients](https://www.elastic.co/guide/en/elasticsearch/client/index.html), which uses the [scan-scroll API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html#scroll-scan) and the [bulk API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html) to pull the data out of the old cluster and index it into the new cluster.

The challenge here from Elasticsearch's prospective is how to perform the 'merge' of the data. If there is a clash between the clusters (i.e. a document already exists on the new cluster when you index from the old cluster) what should ES do? Keep the new one? The old one? or maybe there is something in the document that would indicate which one to keep? These are questions that are much easier for you to answer in a custom application/tool than for Elasticsearch to be able to provide options for out of the box.

---

<div class="post-metadata">

### Author: ![John\_Thornborrow](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@John\_Thornborrow](https://discuss.elastic.co/u/John_Thornborrow)
#### Post date: [August 19, 2015, 10:16am UTC](https://discuss.elastic.co/t/how-to-take-data-from-old-server-and-merge-it-with-data-on-new-server/27658/3 "2015-08-19T10:16:04Z")

</div>

Thanks for the info.

It so happens that our indexes are using GUIDs, so clashes "won't" happen (famous last words?). Though I fully understand the predicament.

Regards,  
John

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [August 19, 2015, 10:19am UTC](https://discuss.elastic.co/t/how-to-take-data-from-old-server-and-merge-it-with-data-on-new-server/27658/4 "2015-08-19T10:19:16Z")

</div>

> [@John\_Thornborrow](#):
>
> It so happens that our indexes are using GUIDs, so clashes "won't" happen (famous last words?).

In which case another option could be to restore the old clusters data to a different index in the new cluster and use an [alias](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html) to query both at the same time.

---

<div class="post-metadata">

### Author: ![John\_Thornborrow](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@John\_Thornborrow](https://discuss.elastic.co/u/John_Thornborrow)
#### Post date: [August 19, 2015, 2:38pm UTC](https://discuss.elastic.co/t/how-to-take-data-from-old-server-and-merge-it-with-data-on-new-server/27658/5 "2015-08-19T14:38:52Z")

</div>

I've gone for the small app option with scroll and bulk API calls, but I notice I am not getting the \_type information - which is quite essential to what we are doing.

I seem to remember ES just simply doesn't return this field in a search - but surely there's a way to force it to do so?

edit: Using c# and NEST.

---

<div class="post-metadata">

### Author: ![John\_Thornborrow](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@John\_Thornborrow](https://discuss.elastic.co/u/John_Thornborrow)
#### Post date: [August 19, 2015, 2:59pm UTC](https://discuss.elastic.co/t/how-to-take-data-from-old-server-and-merge-it-with-data-on-new-server/27658/6 "2015-08-19T14:59:47Z")

</div>

Actually I can see what's happening here.. I am getting he \_id/\_type/etc fields returned, but NEST is not including them when it parses the hits into the Documents collection. This is going to take some wrestling.

---

<div class="post-metadata">

### Author: ![Martijn\_Laarman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martijn_laarman/32/4410_2.png) [@Martijn\_Laarman](https://discuss.elastic.co/u/Martijn_Laarman)
#### Post date: [August 19, 2015, 3:38pm UTC](https://discuss.elastic.co/t/how-to-take-data-from-old-server-and-merge-it-with-data-on-new-server/27658/7 "2015-08-19T15:38:06Z")

</div>

Hey John, the `.Documents` collections is a special view on `.Hits` returning only the `_source`'s for each hit.

Loop over `.Hits` if you need the document metadata.

---

<div class="post-metadata">

### Author: ![John\_Thornborrow](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@John\_Thornborrow](https://discuss.elastic.co/u/John_Thornborrow)
#### Post date: [August 19, 2015, 3:57pm UTC](https://discuss.elastic.co/t/how-to-take-data-from-old-server-and-merge-it-with-data-on-new-server/27658/8 "2015-08-19T15:57:30Z")

</div>

Hi Martijn,

Yes, absolutely right. The end result saw something similar to this:

```
        nestClient.Bulk(new BulkRequest()
        {
            Operations = searchResponse.Hits.Select(x => new BulkIndexOperation
            {
                Id = x.Id,
                Index = x.Index,
                Type = x.Type
            }).Cast<IBulkOperation>().ToList()
        });

```

Inside the scroll loop.

---

<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 5, 2017, 11:54pm UTC](https://discuss.elastic.co/t/how-to-take-data-from-old-server-and-merge-it-with-data-on-new-server/27658/9 "2017-07-05T23:54:56Z")

</div>


