An routing missing exception is obtained when reindex sets the routing value


(steven) #1

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


(steven) #2

i have found a similar issue for this :
Trouble Reindexing Child Documents with join field in ES 5.6;
But I still don't know what's causing this problem?


(steven) #3

At last, i 've found a method to resolving the problem, just like this:

{
"source": {
"index": "report",
"type": "user_mail_action"
},
"dest": {
"index": "report_user"
},
"script": {
"source": "ctx.put('_type','mail_recipient_action');String routingCode=ctx._source.originalTaskCode; Map join = new HashMap(); join.put('name','details');join.put('parent',routingCode); ctx._source.put('relation_type',join);ctx._parent = null; ctx._routing=new StringBuffer(routingCode)"
}
}

and we can see this issue:
https://github.com/elastic/elasticsearch/issues/26183


(system) #4

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