I'm having issues upgrading my solr configuration from 1.5.4 to 3.0.0.M4 (along with a Spring Boot update to 2.0.0.M2).
Previous config file (spring-data-solr 1.5.4.RELEASE):
@Configuration
@EnableSolrRepositories(value = "com.bar.foo.repository.solr", multicoreSupport = true)
public class SolrConfiguration implements EnvironmentAware{
private RelaxedPropertyResolver propertyResolver;
private Environment environment;
@Override
public void setEnvironment(Environment environment) {
this.environment = environment;
this.propertyResolver = new RelaxedPropertyResolver(environment, "spring.data.solr.");
}
@Bean
public SolrServer solrServer() {
String solrHost = propertyResolver.getProperty("host");
return new HttpSolrServer(solrHost);
}
@Bean(name = "core1SolrTemplate")
public SolrOperations core1SolrTemplate() {
HttpSolrServer httpSolrServer = new HttpSolrServer(propertyResolver.getProperty("host"));
return new SolrTemplate(httpSolrServer, "Core1");
}
@Bean(name = "core2SolrTemplate")
public SolrOperations core2SolrTemplate() {
HttpSolrServer httpSolrServer = new HttpSolrServer(propertyResolver.getProperty("host"));
return new SolrTemplate(httpSolrServer, "Core2");
}
...
}
We are then using these solrtemplate in the code as
@Resource SolrTemplate core1SolrTemplate;
@Resource SolrTemplate core2SolrTemplate;
Trying to update, I see that HttpSolrServer is no longer available, and we should use SolrClient, but with the removal of multicoreSupport and the ability to declare the template's core I don't get how to have a template per core (or a single one able to detect which core to query ?)
Here's my current non-working config :
@Configuration
@EnableSolrRepositories(value = "com.bar.foo.repository.solr")
public class SolrConfiguration {
@Inject
private Environment environment;
@Bean
public SolrClient solrClient() {
return new HttpSolrClient.Builder(environment.getProperty("spring.data.solr.host")).build();
}
@Bean
public SolrTemplate solrTemplate() {
return new SolrTemplate(solrClient());
}
}
Our Pojos are configured as :
@SolrDocument(solrCoreName = "Core1")
public class Foo{
@Id
private String id;
...
}
and the call throwing the error
core1SolrTemplate.queryForPage(simpleQuery, Foo.class)
"Caused by: org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://192.168.99.100:8983/solr: Expected mime type application/octet-stream but got text/html. "
It looks like the solrtemplate is only calling the baseurl without selecting any core.
I also tried creating multiple SolrTemplate as before and passing a parameter to the solrClient() to construct a specific url per core but was unsuccessful to make it work (I had errors where the 2nd template was apparently using the first solrtemplate bean, pointing to the wrong core).
How should I configure Solr to be able to query multiple cores ?
Current (2.1.4) solr doc : http://docs.spring.io/spring-data/data-solr/docs/current/reference/html/#solr.multicore
Multicore is not described in the 3.0.0.M4 doc : http://docs.spring.io/spring-data/data-solr/docs/3.0.0.M4/reference/html/#solr.multicore