# Copy routing info from old index to new index

**URL:** <https://discuss.elastic.co/t/copy-routing-info-from-old-index-to-new-index/363320>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 18, 2024, 6:16am UTC](https://discuss.elastic.co/t/copy-routing-info-from-old-index-to-new-index/363320 "2024-07-18T06:16:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhadauria](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhadauria/32/127899_2.png) [@abhadauria](https://discuss.elastic.co/u/abhadauria)\
**Post date:** [July 18, 2024, 6:16am UTC](https://discuss.elastic.co/t/copy-routing-info-from-old-index-to-new-index/363320/1 "2024-07-18T06:16:58Z")

</div>

Hi Team,

We want to reindex the data from older version of index(6.x) to new version(7.x)  
We have created new index using the same settings and mapping in ES cluster 7.17, tried to initiate re-indexing using below request, however we are unable to copy the \_routing info from old index to the new one, we have used below request:

```auto
curl -X POST "localhost:9200/_reindex" -H 'Content-Type: application/json' -d'
{
  "source": {
    "index": "old_index"
  },
  "dest": {
    "index": "new_index"
  },
  "script": {
    "source": "ctx._routing = ctx._source._routing",
    "lang": "painless"
  }
}'

```

can someone please help us by suggesting if we are missing something here or do we need to follow some other steps.

---

<div class="post-metadata">

**Author:** ![abhadauria](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhadauria/32/127899_2.png) [@abhadauria](https://discuss.elastic.co/u/abhadauria)\
**Post date:** [July 18, 2024, 9:23am UTC](https://discuss.elastic.co/t/copy-routing-info-from-old-index-to-new-index/363320/2 "2024-07-18T09:23:31Z")

</div>

can someone please help here as this is a urgent request?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 18, 2024, 10:42am UTC](https://discuss.elastic.co/t/copy-routing-info-from-old-index-to-new-index/363320/3 "2024-07-18T10:42:46Z")

</div>

Please be patient in waiting for responses to your question and refrain from pinging multiple times asking for a response or opening multiple topics for the same question. This is a community forum, it may take time for someone to reply to your question. For more information please refer to the [Community Code of Conduct](https://www.elastic.co/community/codeofconduct) specifically the section "Be patient". Also, please refrain from pinging folks directly, this is a forum and anyone that participates might be able to assist you.

If you are in need of a service with an SLA that covers response times for questions then you may want to consider talking to us about a [subscription](https://www.elastic.co/subscriptions).

It's fine to answer on your own thread after 2 or 3 days (not including weekends) if you don't have an answer.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 18, 2024, 11:33am UTC](https://discuss.elastic.co/t/copy-routing-info-from-old-index-to-new-index/363320/4 "2024-07-18T11:33:43Z")

</div>

This seems to be working well:

```auto
DELETE old_index
DELETE new_index
PUT old_index/_doc/1?routing=abc
{
  "foo": "bar"
}
POST /_reindex
{
  "source": {
    "index": "old_index"
  },
  "dest": {
    "index": "new_index"
  },
  "script": {
    "source": "ctx._routing = ctx._routing",
    "lang": "painless"
  }
}

```

Just note that `_routing` is not a `_source` field but a metadata field.

But that's actually not needed, at least with 8.14.3. This works OOTB:

```auto
POST /_reindex
{
  "source": {
    "index": "old_index"
  },
  "dest": {
    "index": "new_index"
  }
}

```

```auto
GET new_index/_search

```

gives:

```auto
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "new_index",
        "_id": "1",
        "_score": 1,
        "_routing": "abc",
        "_source": {
          "foo": "bar"
        }
      }
    ]
  }
}

```
