如何在solrj中创建新核心
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在solrj中创建新核心相关的知识,希望对你有一定的参考价值。
我正在尝试使用solrj创建新核心。我需要它为我的应用程序准备测试。我认为这段代码不完整或错误,因为每次我收到错误“没有核心候选人”。
package com.itsystems.talentapp.config;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.response.CoreAdminResponse;
import org.apache.solr.core.CoreContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import java.io.IOException;
@Configuration
public class SolrConfig {
@Autowired
SolrClient solrClient;
@Bean
@Profile("test")
public EmbeddedSolrServer embeddedSolrServer() throws IOException, SolrServerException {
String folder = "src/main/resources/solr/";
String coreName = "candidates";
CoreAdminResponse e = new CoreAdminRequest().createCore(coreName, folder, solrClient);
CoreContainer container = new CoreContainer(folder);
container.load();
return new EmbeddedSolrServer(container, "candidates");
}
}
错误:
org.apache.solr.common.SolrException: No such core: candidates
版:
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>6.6.1</version>
</dependency>
答案
我错过了几个文件和cfg。正确的代码:
@Bean
public SolrClient solrClient() throws IOException, SolrServerException {
String folder = "src/main/resources/solr/";
String coreName = "candidates";
CoreContainer container = new CoreContainer(folder);
container.load();
return new EmbeddedSolrServer(container, coreName);
}
以上是关于如何在solrj中创建新核心的主要内容,如果未能解决你的问题,请参考以下文章