I'm trying to connect to Solr index using Solrj and in paticular EmbeddedSolrServer
. My solr.xml
look like this:
<solr>
<cores adminPath="/admin/cores" defaultCoreName="db">
<core default="true" instanceDir="../db/" name="db"/>
</cores>
</solr>
When executing a query command to the server
CoreContainer coreContainer = new CoreContainer("C:\\development\\solr-4.4.0\\example tasks\\solr");
EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, "db");
Collection<SolrCore> cores = coreContainer.getCores();
System.out.println(cores);
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
query.addFacetField("taskType", "taskName");
QueryResponse rsp = server.query(query);
I get the following exception:
Exception in thread "main" org.apache.solr.common.SolrException: No such core: db
The db
core is there and when I start Solr using Jetty and the same solr.xml
file, everything works perfect.
EDIT after comments:
In version 4.4.0 you need to use load()
function to load the cores.
CoreContainer coreContainer = new CoreContainer("C:\\development\\solr-4.4.0\\example tasks\\solr");
container.load();
If you haven't already seen the solr wiki for EmbeddedSolrSever, please have a look.
I hope it solves your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With