无法使用embeddedsolrserver在solrj中创建核心

时间:2013-09-23 07:49:50

标签: solrj

这是我的代码:

File home = new File(System.getProperty("solr.solr.home"));
        CoreContainer container = new CoreContainer(home.getAbsolutePath());
        CoreAdminRequest.Create create = new CoreAdminRequest.Create();
        create.setCoreName("newCoreName");
        create.setCoreNodeName("newCoreName");
        create.setAction(CoreAdminAction.CREATE);
        create.setInstanceDir(home.getAbsolutePath()); 
        create.process(new EmbeddedSolrServer(container, ""));

当我运行它时,我得到“没有这样的核心:”“”异常。 如果我将其更改为:

create.process(new EmbeddedSolrServer(container, "newCoreName"));

我得到“没有这样的核心:”newCoreName“”异常。

请帮帮我......

1 个答案:

答案 0 :(得分:1)

我们发现创建核心需要两件事: 1)必须有一个默认核心 2)应创建用于新核心的目录。

solr.xml如下:

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

要创建新核心,请执行以下操作:

File home = new File(scfg.getIndexHome());
File solr = new File(home, "solr.xml");
String corename = "newcore";
CoreContainer container = new CoreContainer(home, solr);
//create the directory
File f = new File(home, corename); f.mkdirs();
SolrServer server = new EmbeddedSolrServer(container, "empty"); //default
//create the core
CoreAdminRequest.createCore(corename, corename, server, "solrconfig.xml", "schema.xml");
//persist it in the solr.xml
CoreAdminRequest.persist("solr.xml", server);
SolrServer servernew = new EmbeddedSolrServer(container, corename);