Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No such core" exception using EmbeddedSolrServer

Tags:

java

solr

solrj

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.

like image 709
Konstantin Milyutin Avatar asked Oct 02 '22 21:10

Konstantin Milyutin


1 Answers

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.

like image 58
SSaikia_JtheRocker Avatar answered Oct 23 '22 19:10

SSaikia_JtheRocker