如何设置 EmbeddedSolrServer 实例?
我在运行 EmbeddedSolrServer
时遇到问题。至少可以说,CoreContainer
的 JavaDoc 很稀疏。我查看了“MergeIndexesEmbeddedTest”,我的代码似乎应该可以工作。 (这是一个 Maven 项目)我在 src/main/resources 文件夹的根目录中有“Schema.xml”和“solr.xml”。我可以实例化服务器,但是当我尝试将 SolrInputDocument
添加到服务器时,我得到:
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)
我设置服务器的代码是:
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" );
和我的 solr.xml
> 文件是:
<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false">
<cores adminPath="/admin/cores" defaultCoreName="butterfly1">
<core name="butterfly" instanceDir="." />
</cores>
</solr>
我还没有发布我的 Schema.xml
文件,因为它只是示例文件的修剪版本,具有不同的字段名称。我使用绝对文件路径只是因为它看起来更容易开始。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 solr.xml 片段中,默认CoreName 是butterfly1。您的架构中没有名称为 =butterfly1 的核心。
您使用什么版本的 solr 服务器?
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 ?
这种情况主要发生在 时
EmbeddedSolrServer
无法找到核心。通常是因为core.properties
文件丢失(查看 Solr 配置文件)。鉴于有很多事情可能会出错,最近我编写了一个 Java 示例,它可以帮助您编写自己的测试配置、加载数据和运行 junit 测试。
https://github.com/freedev/EmbeddedSolrServer-junit-example
This happens mostly when
EmbeddedSolrServer
is unable to find the core. Usually because thecore.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