How to change routing value for existed routed data?

I have an existed index which is "_routing" required as true. So all data is already routed to particular shards based on "_routing" value. Right now we're using a customized routing value like "organization id" to route the data. However we have a use case that data could be changed from one organization to another organization. For this use case, we need to update the indexing data for organization id , meanwhile we need to re-route data to another particular shards. We cannot use "Update_by_query" , it will show me error like "Modifying _routing not allowed". Any suggestions for right and easy to approach this , update the data itself and change "_routing" also . thanks.

I do not think there is any easy way to do this within Elasticsearch. I suspect you will need to read the data and then delete it before reindexing the updated documents. This will require vide outside Elasticsearch.

I think that's right. An "update" is really just deleting the old doc and indexing the new one, with a few optimisations that use the fact that the old doc and the new doc are in the same shard. If you're changing the routing then you're potentially moving the doc to a different shard, so those optimisations don't work any more and so it's no different from doing the delete-and-index process yourself.

Update-by-query is just running a search to find the docs and then performing an update on each one in turn: it's also something you can implement yourself.

Thanks David, looks like there is no easy way, I have to do delete-and-index for this. thanks.

An index can be configured such that custom routing values will go to a subset of the shards rather than a single shard. This helps mitigate the risk of ending up with an imbalanced cluster while still reducing the impact of searches. This is done by providing the index level setting index.routing_partition_size at index creation

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