Trying to rename the existing fields using reindex api
Works well for non-nested fields:
POST _reindex
{
"source": {
"index": "products-2018.04.05"
},
"dest": {
"index": "products-reindex-2018.04.05"
},
"script": {
"inline": "ctx._source.pid = ctx._source.remove(\"ProductID\")"
}
}
But, when I tried on nested fields, its not working:
POST _reindex
{
"source": {
"index": "products-2018.04.05"
},
"dest": {
"index": "products-reindex-2018.04.05"
},
"script": {
"inline": "ctx._source.PRODUCT.RPT.VALUEAVG = ctx._source.remove(\"PRODUCT.RPT.VALUE.AVG\")"
}
}
Error:
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source.PRODUCT.RPT.VALUEAVG = ctx._source.remove(\"PRODUCT.RPT.VALUE.AVG\")",
" ^---- HERE"
],
"script": "ctx._source.PRODUCT.RPT.VALUEAVG = ctx._source.remove(\"PRODUCT.RPT.VALUE.AVG\")",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
Mapping:
PRODUCT.RPT.VALUEAVG --> text and not-analyzed
I tried different ways, nothing worked:
ctx._source.'PRODUCT.RPT.VALUEAVG'
ctx._source.\"PRODUCT.RPT.VALUEAVG"
ctx._source.[PRODUCT][RPT][VALUEAVG]