0

We are trying to implement a two-dimensional solr cloud cluster where the first dimension is a collection and the second is a shard. Collection should be determined in runtime based on a document properties.

I can see that this functionality is supported by solrj- CloudSolrClient has appropriate methods which accept collection name like add(String collection, SolrInputDocument doc), so I registered @Bean CloudSolrClient("zookeeper.host"). But apparently it isn't enough because methods in SolrTemplate, which is used by Spring Data Solr, doesn't accept a collection name.

Since SolrTemplate uses SolrClient under the hood I tried to workaround this problem extending SolrTemplate and overriding saveBean and saveBeans methods delegating to CloudSolrClient#add(String collection, SolrInputDocument doc) and CloudSolrClient#add(String collection, Collection<SolrInputDocument> docs). It worked fine until I was need to do the same for queries. SolrTemplate#executeSolrQuery is package-private and final, so I can't override it. And here I stuck!

To summarise my question: is there a way to specify a collection name in spring data solr in runtime?

I would greatly appreciate any help!

Regards, Eugeny

Eugeny
  • 1
  • 3

1 Answers1

0

My problem was a bit different, but I had also a problem with collection name in queries and in my case adding @SolrDocument(solrCoreName = "core_to_which_model_class_belong") to model class solved the problem.

Piotr Tempes
  • 1,091
  • 1
  • 12
  • 26
  • But unfortunately it doesn't seem dynamic. I needed to be able to store documents in different collections, not in a predefined one. – Eugeny May 20 '16 at 16:36
  • I was debugging solrj and spring-data-solr code a bit and it seems different solr clients have different approaches. Look at this snippet of code for instance: `if (collection == null)` `collection = (reqParams != null) ? reqParams.get("collection", getDefaultCollection()) : getDefaultCollection();` This is from CloudSolrClient. Seems like you need to provide request param to instruct client to execute your call against chosen collection. However I cannot see any method in spring-data-solr to pass a request. It is created inside solrj – Piotr Tempes May 24 '16 at 10:37
  • Yes, thanks! I've seen this code too. I ended up implementing queries using solrj. – Eugeny May 25 '16 at 10:19