Custom routing above shard count

(Hank Hwang) #1

I'm developing a multi-tenant system and am planning to use custom routing to separate each tenant's data. I created an index with 5 shards. I was wondering what will happen once add a sixth tenant. If I send a query routing to one of the tenants, will the data returned be only from that tenant or will it contain another tenant's data because there are 6 routes with 5 shards?

(Zachary Tong) #2

Routing is simply hash(routing_value) % num_shards. Routing guarantees that all of one tenant's data goes to a single shard, but it doesn't guarantee that other data won't also land there.

In-fact, it's possible that your first two tenants may share the same shard even though there are 5 total shards, just because they happen to hash to the same location.

When custom routing, you will always need some kind of "exclusionary filter" that returns the data you are interested in. So usually, you'll have routing + filter on the user's routing value, group, ID, etc.

GET /tenants/data/_search?routing=userABC
  "query" : {
    "filtered" : {
      "query": { ... },
      "filter": {
         "term": {
            "username": "userABC"

See and for some more details.

(system) #3