Multiple index search. One with routing

Hello,
Is it possible to query multiple indices at the same time, where one of them requires routing?

For example if index1 requires routing but index 2 doesn't.

Get index1,index2/_search?routing=..?

Thanks

That would work, without the routing, as it'd just search all of the shards in each index.

How many primary shards do the different indices have?

Index1 (alias) has 5 per rolled index.
Index 2 has 1 primary, so im trying to be efficient with index1
Thanks!

The routing parameter determines which of the primary shards that will be queried and allows you to colocate related data and query a minimum of shards. If an index only has one primary shard all possible routing parameters will resolve to that shard so in this case I would expect you to get the same results if you used the routing parameter for all indices as if you did not use it al all and instead queried all shards. If the index without routing had more than one primary shard this would no longer be the case.

I think they may be a solution with a constant keyword field.
What if I add a new constant field to each index (index_type for example) and add the routing to the query body instead of to query string?

Something like
index_type=index1 AND _routing=[client] OR index_type=index2

Reference: example from the documentation

GET my-index-000001/_search
{
  "query": {
    "terms": {
      "_routing": [ "user1" ] 
    }
  }
}

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