开发者

how to setup a EmbeddedSolrServer instance?

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:

or开发者_Go百科g.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.


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 ?


This happens mostly when EmbeddedSolrServer is unable to find the core. Usually because the core.properties file is missing (have a look at Solr configuration files).

Given that are many things that can go wrong, recently I wrote a Java example that helps to write your own test configuration, load data and run junit tests.

https://github.com/freedev/EmbeddedSolrServer-junit-example

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜