Limiting search to few shards by providing routing IDs

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

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.

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