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