1

Is there a way we can add documents into a specific shard?

For example, documents type A will always get inserted into shard1 and document type B always go to shard2.

I have tried using custom router but it does not guaranty that different prefix will route to different shard.

PS. I am on Solr 5 using cloud mode.

TLJ
  • 4,525
  • 2
  • 31
  • 46
  • Did you ever find an answer to this? I'm struggling with the same issue using Solr 5.1.0 in cloud mode. – LandonC Jun 05 '15 at 16:34
  • @LandonC Turned out I live with random shards and multiple redundancy... if you find a solution, let me know :-) – TLJ Jun 08 '15 at 23:07
  • With the help of some other folks, I have what I _believe_ is a solution. It works in a test scenario, that much I know. I'll post below. – LandonC Jun 10 '15 at 01:53

1 Answers1

3

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.

Community
  • 1
  • 1
LandonC
  • 889
  • 1
  • 16
  • 28