Copy routing info from old index to new index

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:

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.

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

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 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.

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

1 Like

This seems to be working well:

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:

POST /_reindex
{
  "source": {
    "index": "old_index"
  },
  "dest": {
    "index": "new_index"
  }
}
GET new_index/_search

gives:

{
  "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"
        }
      }
    ]
  }
}