Redistribute documents with custom routing and reindex API

I have an index with 3 shards, with default routing.

Now, I want to use a custom route (let says field "userID").

How can I use _reindex API to achieve this?

Thanks you,

PS: I saw there is a routing options for reindex API, but it seems you cannot specify document field in it ;/

You can do it with scripts. It'd look something like:

POST _reindex
{
  "source": {
    "index": "old"
  },
  "dest": {
    "index": "new"
  },
  "script": {
    "inline": "ctx._routing = doc.whatever.value"
  }
}
2 Likes

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