如何在 solrj 中创建新核心 [英] How to create new core in solrj
本文介绍了如何在 solrj 中创建新核心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 solrj 创建新核心.我需要它来为我的应用程序准备测试.我认为这段代码不完整或错误,因为每次我收到错误没有核心候选人".
I am trying to create new core using solrj. I need it to prepare test for my app. I think this code is incomplete or wrong because every time I got a error "no core candidates".
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.正确代码:
I missed few files and cfg. Correct code:
@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 中创建新核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文