# Multiple index search. One with routing

**URL:** https://discuss.elastic.co/t/multiple-index-search-one-with-routing/272204
**Category:** Elasticsearch
**Created:** [May 5, 2021, 2:09pm UTC](https://discuss.elastic.co/t/multiple-index-search-one-with-routing/272204 "2021-05-05T14:09:01Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![liorg2](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@liorg2](https://discuss.elastic.co/u/liorg2)
#### Post date: [May 5, 2021, 2:09pm UTC](https://discuss.elastic.co/t/multiple-index-search-one-with-routing/272204/1 "2021-05-05T14:09:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [May 6, 2021, 12:19am UTC](https://discuss.elastic.co/t/multiple-index-search-one-with-routing/272204/2 "2021-05-06T00:19:39Z")

</div>

> [@liorg2](#):
>
> Get index1,index2/\_search

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

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [May 6, 2021, 4:53am UTC](https://discuss.elastic.co/t/multiple-index-search-one-with-routing/272204/3 "2021-05-06T04:53:44Z")

</div>

How many primary shards do the different indices have?

---

<div class="post-metadata">

### Author: ![liorg2](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@liorg2](https://discuss.elastic.co/u/liorg2)
#### Post date: [May 6, 2021, 6:17am UTC](https://discuss.elastic.co/t/multiple-index-search-one-with-routing/272204/4 "2021-05-06T06:17:53Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [May 6, 2021, 6:43am UTC](https://discuss.elastic.co/t/multiple-index-search-one-with-routing/272204/5 "2021-05-06T06:43:25Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![liorg2](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@liorg2](https://discuss.elastic.co/u/liorg2)
#### Post date: [May 6, 2021, 7:20am UTC](https://discuss.elastic.co/t/multiple-index-search-one-with-routing/272204/6 "2021-05-06T07:20:06Z")

</div>

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"] 
    }
  }
}
```

---

<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: [June 3, 2021, 7:21am UTC](https://discuss.elastic.co/t/multiple-index-search-one-with-routing/272204/7 "2021-06-03T07:21:08Z")

</div>

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