Reindexing: Move mapping up a level

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

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

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

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 field:

  "source": {
    "index": "temp1"
  "dest": {
    "index": "temp2"
  ,"script": {
    "source": "if ( instanceof String) {String;['name':host];}"

see for the specification of Painless

Hope this helps

Thanks so much!

Got it.

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

Thanks again.

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