5

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.

4

3 回答 3

4

评论后编辑:

在 4.4.0 版本中,您需要使用load()函数来加载内核。

CoreContainer coreContainer = new CoreContainer("C:\\development\\solr-4.4.0\\example tasks\\solr");
container.load();

如果您还没有看过EmbeddedSolrSever 的 solr wiki,请看一下。

我希望它能解决你的问题。

于 2013-09-21T18:29:36.630 回答
0

从 Solr 4.4 开始,有另一种使用核心目录和 core.properties 文件发现的核心定义方法。从 Solr 5.0 开始,此方法是强制性的。

注意:您在 solr.xml 中的核心定义需要迁移到新方法。有关更多信息,请参阅Solr.xml 4.4 及更高版本

于 2015-06-10T09:13:29.850 回答
0

这主要发生在EmbeddedSolrServer无法找到核心时。通常是因为core.properties文件丢失(查看Solr 配置文件)。

我写了一个 Java 示例,它可以帮助您编写自己的测试配置、加载数据和运行 junit 测试。

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

于 2021-01-21T07:55:05.353 回答