Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleSolrRepository.save throws SolrServerException: No collection param specified on request and no default collection has been set [DATASOLR-349] #473

Open
spring-projects-issues opened this issue Dec 30, 2016 · 0 comments
Assignees
Labels
in: core type: enhancement

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Dec 30, 2016

jefferyyuan opened DATASOLR-349 and commented

Previously my solr configuration is like this:
public SolrClient solrClient() {
return new CloudSolrClient(zkHost);
}
@Bean(name = "abcTemplate")
public SolrOperations coreAbcTemplate() {
return new SolrTemplate(solrClient(), "coreAbc");
}

@Bean(name = "core123Template")
public SolrOperations core123Template() {
return new SolrTemplate(solrClient(), "core123");
}

But my solrRepository.save(which extends SimpleSolrRepository) throws SolrServerException: No collection param specified on request and no default collection has been set

Usually an application talks to multiple solr collections.
SolrClient is shared by multiple SolrTemplate.

SimpleSolrRepository is bounded to a specific SolrTemplate, a specific solr collection.
SolrTemplate is bounded to a specific collection: private String solrCore

org.springframework.data.solr.repository.support.SimpleSolrRepository.save(S)
commitIfTransactionSynchronisationIsInactive calls this.solrOperations.commit() which calls commit on SolrClient
It will commit to the default collection it we set the default collection when create SolrClientm otherwise it will throw exception:
org.apache.solr.client.solrj.SolrServerException: No collection param specified on request and no default collection has been set.

The logic is not right - it should commit on its SolrTemplate's solr collection not default solr collection.

IMHO, org.springframework.data.solr.repository.support.SimpleSolrRepository.commitIfTransactionSynchronisationIsInactive() should call solrOperations.commit(solrOperations.getSolrCore()); // maybe also expose getSolrCore in SolrOperations.

My workaround is to change solr configuration like this:
@Bean(name = "abcTemplate")
public SolrOperations searchHistoryTemplate() {
final CloudSolrClient solrClient = new CloudSolrClient(zkHost);
solrClient.setDefaultCollection("coreAbc");
return new SolrTemplate(solrClient, "coreAbc");
}

@Bean(name = "core123Template")
public SolrOperations programsTemplate() {
final CloudSolrClient solrClient = new CloudSolrClient(zkHost);
solrClient.setDefaultCollection("core123");
return new SolrTemplate(solrClient, "core123");
}

It works, but I kind of don't like it - as it creates one CloudSolrClient for each solr collection.
IMHO, SolrClient should be (at lease be able) shared by all solrTemplates


No further details from DATASOLR-349

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants