gpt4 book ai didi

java - Spring boot在elasticsearch TransportClient启动时抛出Netty4HttpServerTransport异常

转载 作者:行者123 更新时间:2023-12-02 10:10:13 25 4
gpt4 key购买 nike

我正在尝试使用 Spring boot(版本 2)将我的项目转换为基于 REST 的项目。原始项目用于使用 Elasticsearch (6.6.1)进行文本搜索,并且它按预期工作。然后在‘spring boot starter web项目’中,我引入了一个RESTController来调用上面的TextSearch类

请查看相关类(class)

public class TextSearch {
private final TransportClient client;
public static final Logger LOGGER = LoggerFactory.getLogger(TextSearch.class);

public TextSearch() {
Settings settings = Settings.builder().put("cluster.name", "elasticsearch").put("client.transport.sniff", true).build();
client= new PreBuiltTransportClient(settings);
try {
client.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));
}catch (UnknownHostException e) {
LOGGER.error("Unknown host exception {}", e);
}
}
}
// spring rest controller class
@RestController
public class SearchController {


@RequestMapping("/search")
public String search(@RequestParam(value="name", defaultValue="World") String name) {

List<SCMappedData> mappedList = FetchScDataJsoup.fetch();
System.out.println("#######no of entries" + mappedList.size());
TextSearch textSearch = new TextSearch("legal", "sc");
boolean indexCreation = textSearch.createIndex(mappedList);

List<SearchHit> hits = textSearch.search(name);
for (SearchHit hit:hits
) {
System.out.println(hit.getSourceAsString());
}
if(hits.size() > 0) {
return hits.get(0).getExplanation().getDescription();
} else {
return " nt found";
}

}
}

但是获取请求失败并出现以下错误

java.lang.NoSuchFieldError: Shared
at org.elasticsearch.http.netty4.Netty4HttpServerTransport.<clinit>(Netty4HttpServerTransport.java:124) ~[transport-netty4-client-5.6.11.jar:5.6.11]
at org.elasticsearch.transport.Netty4Plugin.getSettings(Netty4Plugin.java:55) ~[transport-netty4-client-5.6.11.jar:5.6.11]
at org.elasticsearch.plugins.PluginsService.lambda$getPluginSettings$0(PluginsService.java:89) ~[elasticsearch-6.6.1.jar:6.6.1]
at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:271) ~[na:na]
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1492) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na]
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[na:na]
at org.elasticsearch.plugins.PluginsService.getPluginSettings(PluginsService.java:89) ~[elasticsearch-6.6.1.jar:6.6.1]
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:147) ~[elasticsearch-6.6.1.jar:6.6.1]
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:288) ~[elasticsearch-6.6.1.jar:6.6.1]
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:128) ~[transport-6.6.1.jar:6.6.1]
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:114) ~[transport-6.6.1.jar:6.6.1]
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:104) ~[transport-6.6.1.jar:6.6.1]
at search.TextSearch.<init>(TextSearch.java:40) ~[classes/:na]
at run.SearchController.search(SearchController.java:25) ~[classes/:na]

我知道我可能需要提供更多详细信息才能得到答案,但我不确定我必须提供哪些详细信息。

这是我第一次尝试使用 Spring 项目。因此我想知道是否有人可以就此提供高水平的建议。

最佳答案

查看异常堆栈跟踪,ElasticSearch 版本与 netty 客户端不匹配。所以使用相同的版本。

<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>transport-netty4-client</artifactId>
<version>6.6.1</version>
</dependency>

关于java - Spring boot在elasticsearch TransportClient启动时抛出Netty4HttpServerTransport异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55053298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com