Elasticsearch Reindex to New map [6.2]

Hello,

I'm looking for a solution to reindex to new mapping.
My old map look like this
{
"user": {
"id": 1,
"email": "example@mail.com",
"role": "ROLE",
}
}

how can I achieve and change it too
{
"userId": 1
}

Thank You.

I think you are looking for: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#docs-reindex-change-name

For example:

DELETE old
DELETE new
PUT old/_doc/1
{
  "user": {
    "id": 1,
    "email": "example@mail.com",
    "role": "ROLE"
  }
}

GET old/_doc/1
POST _reindex
{
  "source": {
    "index": "old"
  },
  "dest": {
    "index": "new"
  },
   "script": {
    "source": "ctx._source.user.userId = ctx._source.user.remove('id')",
    "lang": "painless"
  }
}
GET new/_doc/1

results in

{
  "_index": "new",
  "_type": "_doc",
  "_id": "1",
  "_version": 1,
  "found": true,
  "_source": {
    "user": {
      "role": "ROLE",
      "userId": 1,
      "email": "example@mail.com"
    }
  }
}

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