我期待将 Elasticsearch 集成到 Spring Boot Web 应用程序中。这是创建传输客户端的配置:
@Configuration
public class ElasticsearchConfig {
private TransportClient client;
@Bean
public TransportClient client() throws UnknownHostException{
Settings settings = Settings.builder()
.put("client.transport.nodes_sampler_interval", "5s")
.put("client.transport.sniff", false)
.put("transport.tcp.compress", true)
.put("cluster.name", "clusterName")
.put("xpack.security.transport.ssl.enabled", true)
.build();
client = new PreBuiltTransportClient(settings);
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
return client;
}
当我启动项目时,出现以下错误,但我不知道为什么:
java.lang.ClassNotFoundException: org.elasticsearch.plugins.NetworkPlugin
我是否忘记添加依赖项?
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.1.1</version>
</dependency>
希望你能帮我
我刚刚偶然发现了同样的问题。 Elasticsearch 文档似乎不完整。除了传输客户端依赖项之外,您还需要添加elasticsearch依赖项:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.1.1</version>
</dependency>
您还需要 log4j 依赖项,但这在Elasticsearch 文档 https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/_log4j_2_logger.html.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)