A caveat: I'm using SolrNet to access SolrCloud, and it doesn't integrate with ZooKeeper yet. For Java clients, this might be far easier.
Despite what I read here and here with regard to the CompositeId Router
, I could never get it to work. What @jay helped me figure out is a way to use "implicit" routing to achieve this. If you create your collection like this (leave out the numShards
parameter):
http://localhost:8983/solr/admin/collections?action=CREATE&name=myCol&maxShardsPerNode=2&router.name=implicit&shards=shard1,shard2&router.field=shard
then add a field to your schema.xml
named "shard" (matching the router.field
parameter), you can index to a specific shard simply by adding the shard
field to the document being indexed and specifying the shard name. At query time, you can specify shards
to search -- more here (I was able to simply specify the shard name w/o a specific address).
I haven't tested this in production yet, but have verified using multiple VirtualBox instances, with ZooKeeper, HAProxy, and several Solr nodes, and it's doing exactly what I expected. Corrections and comments welcome.