# Limiting search to few shards by providing routing IDs

**URL:** <https://discuss.elastic.co/t/limiting-search-to-few-shards-by-providing-routing-ids/99709>\
**Category:** Elasticsearch\
**Created:** [September 7, 2017, 10:29am UTC](https://discuss.elastic.co/t/limiting-search-to-few-shards-by-providing-routing-ids/99709 "2017-09-07T10:29:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vivek7mehta](https://avatars.discourse-cdn.com/v4/letter/v/51bf81/32.png) [@vivek7mehta](https://discuss.elastic.co/u/vivek7mehta)\
**Post date:** [September 7, 2017, 10:29am UTC](https://discuss.elastic.co/t/limiting-search-to-few-shards-by-providing-routing-ids/99709/1 "2017-09-07T10:29:28Z")

</div>

I am not sure if this question is already asked, I tried to search and couldn't find what I was looking for.  
I am using routing to reduce my search impact. I am providing routing IDs while indexing (e.g. user1, user2, user3....).  
So if I want to search documents I can search it as:

GET my\_index/\_search?routing=user1,user2  
{  
 "query": {  
  "match": {  
   "title": "document"  
   }  
  }  
}

Now my questions are:

1. how can I search on all routing IDs except specific set of routing IDs? (e.g. I want to search on all IDs except user1, user2 and user3) ?
2. If I use \_routing field in the query will it use routing at all?

GET my\_index/\_search  
{  
 "query": {  
  "bool": {  
   "must\_not": [  
    {  
     "terms": {  
      "\_routing": [  
        "user1",  
        "user2",  
        "user3"  
       ]  
      }  
    }  
   ],  
   "must": [  
    {  
     "match": {  
      "title": "document"  
      }  
    }  
   ]  
  }  
 }  
}

---

<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:** [September 7, 2017, 10:39am UTC](https://discuss.elastic.co/t/limiting-search-to-few-shards-by-providing-routing-ids/99709/2 "2017-09-07T10:39:50Z")

</div>

The main benefit of routing is that you can hit a single shard instead of all. If you are likely to hit the majority of all shards, just query without routing.

---

<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:** [October 5, 2017, 10:39am UTC](https://discuss.elastic.co/t/limiting-search-to-few-shards-by-providing-routing-ids/99709/3 "2017-10-05T10:39:51Z")

</div>

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