Renaming fields in elasticsearch
The Request
field does not yet exist in your documents, so your script needs to create it first:
POST _reindex
{
"source": {
"index": "testindex"
},
"dest": {
"index": "testindex1"
},
"script": {
"inline": "ctx._source.Request = [:]; ctx._source.Request.field3 = ctx._source.remove(\"field2\") ]"
}
}
Or a bit shorter like this:
POST _reindex
{
"source": {
"index": "testindex"
},
"dest": {
"index": "testindex1"
},
"script": {
"inline": "ctx._source.Request = [field3: ctx._source.remove(\"field2\") ]"
}
}