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

**URL:** <https://discuss.elastic.co/t/an-routing-missing-exception-is-obtained-when-reindex-sets-the-routing-value/155140>\
**Category:** Elasticsearch\
**Created:** [November 2, 2018, 9:42am UTC](https://discuss.elastic.co/t/an-routing-missing-exception-is-obtained-when-reindex-sets-the-routing-value/155140 "2018-11-02T09:42:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lwpk110](https://avatars.discourse-cdn.com/v4/letter/l/e68b1a/32.png) [@lwpk110](https://discuss.elastic.co/u/lwpk110)\
**Post date:** [November 2, 2018, 9:42am UTC](https://discuss.elastic.co/t/an-routing-missing-exception-is-obtained-when-reindex-sets-the-routing-value/155140/1 "2018-11-02T09:42:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lwpk110](https://avatars.discourse-cdn.com/v4/letter/l/e68b1a/32.png) [@lwpk110](https://discuss.elastic.co/u/lwpk110)\
**Post date:** [November 5, 2018, 2:49am UTC](https://discuss.elastic.co/t/an-routing-missing-exception-is-obtained-when-reindex-sets-the-routing-value/155140/2 "2018-11-05T02:49:00Z")

</div>

i have found a similar issue for this ：  
[Trouble Reindexing Child Documents with join field in ES 5.6](https://discuss.elastic.co/t/trouble-reindexing-child-documents-with-join-field-in-es-5-6/143568);  
But I still don't know what's causing this problem?

---

<div class="post-metadata">

**Author:** ![lwpk110](https://avatars.discourse-cdn.com/v4/letter/l/e68b1a/32.png) [@lwpk110](https://discuss.elastic.co/u/lwpk110)\
**Post date:** [November 5, 2018, 4:14am UTC](https://discuss.elastic.co/t/an-routing-missing-exception-is-obtained-when-reindex-sets-the-routing-value/155140/3 "2018-11-05T04:14:16Z")

</div>

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](https://github.com/elastic/elasticsearch/issues/26183)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 3, 2018, 4:14am UTC](https://discuss.elastic.co/t/an-routing-missing-exception-is-obtained-when-reindex-sets-the-routing-value/155140/4 "2018-12-03T04:14:17Z")

</div>

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