# Best practices around moving documents between indices

**URL:** <https://discuss.elastic.co/t/best-practices-around-moving-documents-between-indices/123321>\
**Category:** Elasticsearch\
**Created:** [March 9, 2018, 6:26pm UTC](https://discuss.elastic.co/t/best-practices-around-moving-documents-between-indices/123321 "2018-03-09T18:26:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Leary](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@Andrew\_Leary](https://discuss.elastic.co/u/Andrew_Leary)\
**Post date:** [March 9, 2018, 6:26pm UTC](https://discuss.elastic.co/t/best-practices-around-moving-documents-between-indices/123321/1 "2018-03-09T18:26:02Z")

</div>

Hi all,

I have a question about the best approach to move data between indices when the mapping needs to be updated--I'm working with version 5.5. As an example, let's say I have my\_index\_v1 setup like this:

```
my_index_v1 {
  "mapping": {
    "my_type": {
      "properties": {
        "field_one": {
           "type": "text"
        },
         "time_stamp": {
            "type": "date"
         }
      }
    }
  }
}

```

Now, my plan was to create my\_index\_v2, with a field\_one property set to type "keyword", and then reindex my\_index\_v1 into my\_index\_v2, so that all of the documents in my\_index\_v1 would be moved to my\_index\_v2 with the correct mappings. This however doesn't actually seem to be possible, since when I go to create the new index with the updated mappings, exceptions are thrown on fields with the same name between the two indices (which are also of the same document type).

My question then is, what is the best approach to moving documents from one index to another when the type has to change? For example, would it work to create my\_index\_v2 with a property field\_one\_v2 with the desired mapping, and during the reindex process, have everything stored in field\_one, inserted into field\_one\_v2? Or is my only real option to create my new index with properties that have a different name, then use the scroll API to pull down documents from my\_index\_v1, map the fields returned to the fields in my\_index\_v2 and then upload them to my\_index\_v2?

Thanks!

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [March 11, 2018, 8:49pm UTC](https://discuss.elastic.co/t/best-practices-around-moving-documents-between-indices/123321/2 "2018-03-11T20:49:37Z")

</div>

There should be no problems with having the same field names defined in the mappings of two document types with the same name across two indexes. The following works fine:

```auto
PUT my_index_v1
{
  "mappings": {
    "my_type": {
      "properties": {
        "field_one": {
          "type": "text"
        },
        "time_stamp": {
          "type": "date"
        }
      }
    }
  }
}

PUT my_index_v1/my_type/1
{
  "field_one": "Hello world!"
}

PUT my_index_v2
{
  "mappings": {
    "my_type": {
      "properties": {
        "field_one": {
          "type": "keyword"
        },
        "time_stamp": {
          "type": "date"
        }
      }
    }
  }
}

POST _reindex
{
  "source": {
    "index": "my_index_v1"
  },
  "dest": {
    "index": "my_index_v2"
  }
}

GET my_index_v2/my_type/1

GET my_index_v2/_mapping

```

What are the exceptions you are getting?

---

<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:** [April 8, 2018, 8:50pm UTC](https://discuss.elastic.co/t/best-practices-around-moving-documents-between-indices/123321/3 "2018-04-08T20:50:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
