when i reindex a parent-child relation document from v2.4 to v5.6,i write a script to do it, like this:
_reindex POST
{
"source": {
"index": "report",
"type": "user_mail_action"
},
"dest": {
"index": "report_user"
},
"script": {
"source": "ctx.put('_type','mail_recipient_action');ctx.remove('_routing');ctx.remove('_parent');String routingCode=ctx._source.originalTaskCode; Map join = new HashMap(); join.put('name','details');join.put('parent',routingCode); ctx._source.put('relation_type',join);ctx.put('_routing','11111')"
}
}
it works ok..
when i replace ctx.put('_routing','11111')
to ctx.put('_routing',routingCode)
, like this:
{
"source": {
"index": "report",
"type": "user_mail_action"
},
"dest": {
"index": "report_user"
},
"script": {
"source": "ctx.put('_type','mail_recipient_action');ctx.remove('_routing');ctx.remove('_parent');String routingCode=ctx._source.originalTaskCode; Map join = new HashMap(); join.put('name','details');join.put('parent',routingCode); ctx._source.put('relation_type',join);ctx.put('_routing',routingCode)"
}
}
it throws exception like this:
{
"index": "report_user",
"type": "mail_recipient_action",
"id": "AWFvdzJLfh1Fkkb_Jueh",
"cause": {
"type": "mapper_parsing_exception",
"reason": "failed to parse",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "[routing] is missing for join field [relation_type]"
}
},
"status": 400
},
.....
it shows that 'routing' is missing,i can't understand it.when i provide "_routing = '11111'" ,it's ok,but when i provide Dynamic value, it throws err. Did I make any mistakes with this script? thanks ...