Reputation: 334
I have created 2 indices, say user_1 and user_2 with 1 shard and 1 replica, and an alias user_alias that points to both the above indices.
"actions" : [
{ "add" : { "index" : "user_1", "alias" : "user_indexing", "routing": "1"} },
{ "add" : { "index" : "user_2", "alias" : "user_indexing", "routing": "2"} }
]
When doing a _search on user_alias using routing key 1 :
curl -H "Content-Type: application/json" -XGET "localhost:9200/user_alias/_search?routing=1&pretty"
I am getting documents with _routing=2 as well. Is this the expected behaviour?
Basically , I would like to limit the number of shards that executes the search query using routing. Only here, I have used multiple indices with 1 shard, and use routing to select between shards of different indices.
Upvotes: 0
Views: 141
Reputation: 334
Upon further investigation, I found out that since I had only 1 primary shard configured for the index, hence documents with both the routing keys were located on the same shard. And since routing key basically routes you to the shard where it's documents lives (which can be co-located with documents with a different routing key), hence I was getting all the documents that were on the shard (i.e. with routing keys 1 and 2).
Upvotes: 0