Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to setup a EmbeddedSolrServer instance?

Tags:

java

solr

lucene

I am having trouble getting an EmbeddedSolrServer to run. The JavaDoc for CoreContainer is sparse to say the least. I've looked at the "MergeIndexesEmbeddedTest" and my code seems like it should work. (This is a Maven project) I have both "Schema.xml" and "solr.xml" in the root of the src/main/resources folder. I can able to instantiate ther server, but when I try to add a SolrInputDocument to the the server I get:

org.apache.solr.common.SolrException: 'No such core: butterfly'
at org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.request(EmbeddedSolrServer.java:104)
at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:105)
at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:64)

My code that sets up the server is:

final File solrConfigXml = new File( "C:/code/butterfly/src/main/resources/solr.xml" );
final String solrHome = "C:/code/butterfly/src/main/resources/";
CoreContainer coreContainer;
try{
    coreContainer = new CoreContainer( solrHome, solrConfigXml );
}catch( Exception e ){
    e.printStackTrace( System.err );
    throw new RuntimeException( e );
}
solrServer = new EmbeddedSolrServer( coreContainer, "butterfly" );

and my solr.xml file is:

<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false">
    <cores adminPath="/admin/cores" defaultCoreName="butterfly1">
          <core name="butterfly" instanceDir="." />
    </cores>
</solr>

I haven't posted my Schema.xml file since it is just a pruned version of the example one with different field names. I am using absolute files path just because it seemed easier to just get started.

like image 217
Sled Avatar asked Nov 04 '22 20:11

Sled


1 Answers

In your solr.xml snippet, the defaultCoreName is butterfly1. There is no core with name =butterfly1 in your schema.

What version of solr server are you using ?

like image 78
randroid Avatar answered Nov 14 '22 15:11

randroid