# Update\_by\_query and routing

**URL:** <https://discuss.elastic.co/t/update-by-query-and-routing/94869>\
**Category:** Elasticsearch\
**Created:** [July 27, 2017, 9:53pm UTC](https://discuss.elastic.co/t/update-by-query-and-routing/94869 "2017-07-27T21:53:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulieMac](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pauliemac/32/19480_2.png) [@PaulieMac](https://discuss.elastic.co/u/PaulieMac)\
**Post date:** [July 27, 2017, 9:53pm UTC](https://discuss.elastic.co/t/update-by-query-and-routing/94869/1 "2017-07-27T21:53:32Z")

</div>

Hi all,

I have an index with custom routing on it... I've added a new field, and I need to use a script to derive the value that will populate it. I figured an update\_by\_query might be the way to go - but it seems to be impossible? I get the following error:  
`"type":"routing_missing_exception","reason":"routing is required for [weatherb]/[daily]/[_updatebyquery]"`

The script itself works - I've run the update against an index with no routing on it.

The `ctx._routing = ctx._source.wsid;` line in the script is copied from when I originally reindexed into the routed version...

Anyone know a solution? Or do I just bite the bullet and do a \_reindex?

```auto
curl -X POST localhost:9200/weatherb/daily/_updatebyquery -d '
{
	"script" : { 
		"inline": "ctx._routing = ctx._source.wsid; ctx._source.md = ctx._source.date.substring(5, 7) + ctx._source.date.substring(8, 10);", 
		"lang": "painless" 
	}
}'

```

---

<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:** [August 24, 2017, 9:53pm UTC](https://discuss.elastic.co/t/update-by-query-and-routing/94869/2 "2017-08-24T21:53:34Z")

</div>

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