# Reindexing: Move mapping up a level

**URL:** <https://discuss.elastic.co/t/reindexing-move-mapping-up-a-level/258327>\
**Category:** Elasticsearch\
**Created:** [December 10, 2020, 7:10pm UTC](https://discuss.elastic.co/t/reindexing-move-mapping-up-a-level/258327 "2020-12-10T19:10:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![F\_Doe\_FW](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/f_doe_fw/32/77781_2.png) [@F\_Doe\_FW](https://discuss.elastic.co/u/F_Doe_FW)\
**Post date:** [December 10, 2020, 7:10pm UTC](https://discuss.elastic.co/t/reindexing-move-mapping-up-a-level/258327/1 "2020-12-10T19:10:46Z")

</div>

Greetings!  
I am trying to remap an index that inadvertently had a top level 'doc' node.  
So, the documents were indexed like this :

```auto
"_source" : {
          "doc" : {
            "week_starting" : "2020-05-24",
            "origin_zip3" : "020",
            "dest_zip3" : "722", ...

```

when the doc node should have been excluded from the import.

Is there a way to reindex and remap values? Its about 37 million records, so something in place would be great.

Here is kind of a snippet that makes sense to me, if doable, but I can't figure out if anything like this is workable.

```auto
  POST _reindex
 {
 	"size": 1,
    "source": {
      "index": [
        "source_index_1"
      ],
      "_source": [
        "doc"
      ]
    },
    "dest": {
      "index": "dest_index"
 	 {can I do mapping here with simple object notation?: (field1 = source.doc.field1)}
    }
  }

```

---

<div class="post-metadata">

**Author:** ![Shaoranlaos](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Shaoranlaos](https://discuss.elastic.co/u/Shaoranlaos)\
**Post date:** [December 11, 2020, 11:05am UTC](https://discuss.elastic.co/t/reindexing-move-mapping-up-a-level/258327/2 "2020-12-11T11:05:39Z")

</div>

You can use a Painless script in the redinex process to remap your fields. Here is an example for a remap that i had to do to map the old host field into a new host.name field:

```auto
    {
  "source": {
    "index": "temp1"
  },
  "dest": {
    "index": "temp2"
  }
  ,"script": {
    "source": "if (ctx._source.host instanceof String) {String host=ctx._source.host;ctx._source.host=['name':host];}"
  }
}

```

see [https://www.elastic.co/guide/en/elasticsearch/painless/7.10/painless-lang-spec.html](https://www.elastic.co/guide/en/elasticsearch/painless/7.10/painless-lang-spec.html) for the specification of Painless

Hope this helps

---

<div class="post-metadata">

**Author:** ![F\_Doe\_FW](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/f_doe_fw/32/77781_2.png) [@F\_Doe\_FW](https://discuss.elastic.co/u/F_Doe_FW)\
**Post date:** [December 11, 2020, 2:59pm UTC](https://discuss.elastic.co/t/reindexing-move-mapping-up-a-level/258327/3 "2020-12-11T14:59:44Z")

</div>

Thanks so much!

Got it.

I was having trouble figuring out the mapping from one ctx object to another.

Thanks again.

---

<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:** [January 8, 2021, 2:59pm UTC](https://discuss.elastic.co/t/reindexing-move-mapping-up-a-level/258327/4 "2021-01-08T14:59:47Z")

</div>

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