Adding a field by merging existing field while reindexing

I have an index to which i need to add a field which will merge three existing fields from the same index. Example field1, field2, field3 so unique_field=field1,field2,field3.
I am trying below script along with reindexing which gives me error.
POST _reindex
{
"source":{
"index" : "old"
},
"dest": {
"index": "new"
},
"script": {
"inline": "ctx._source.unique_field=ctx_source.field1+ ',' + ctx._source.field2+ ',' + ctx._source.field3",
"lang": "painless"
}
}

Throws error like -> "error": {
"root_cause": [
{
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... tx._source.unique_field=ctx_source.field1+ ...",
" ^---- HERE"
],
"script": "ctx._source.unique_field=ctx_source.field1+ ',' + ctx._source.field2+ ',' + ctx._source.field3",
"lang": "painless"
}
],
"type": "script_exception",
"reason": "compile error",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Variable [ctx_source] is not defined."
},
"script_stack": [
"... tx._source.unique_field=ctx_source.application + ...",
" ^---- HERE"
],
"script": "ctx._source.unique_action=ctx_source.application + ',' + ctx._source.subsystem + ',' + ctx._source.action",
"lang": "painless"
},
"status": 500

Hi @rahul_raj,

There is a missing '.' (dot) in the script, ctx_source.field1 should be ctx._source.field1.

Looks like there is a missing separator between ctx and _source. You inline script should be "ctx._source.unique_field=ctx._source.field1+ ',' + ctx._source.field2+ ',' + ctx._source.field3" so replacing ctx_source.field1by ctx._source.field1 should fix the problem.

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