如何使用Spring Boot 2.15正确配置Elasticsearch 7.1.1?

时间:2019-06-16 10:41:38

标签: java spring-boot ubuntu elasticsearch

我正在将Elasticsearch 7.1.1与spring-boot 2.1.5结合使用。我下载并运行了Elasticsearch。当我启动spring项目时,出现错误。 “ 无法加载Elasticsearch节点:org.elasticsearch.client.transport.NoNodeAvailableException:没有配置的节点可用:[{#transport#-1} {rsi4dYt_RuOBGCdwUH3Cgg} {127.0.0.1} {127.0.0.1 :9200}] ”。我该如何正确磨碎

我使用了这些配置。

spring.elasticsearch.jest.multi-threaded=true
spring.main.allow-bean-definition-overriding=true
spring.data.elasticsearch.cluster-nodes=localhost:9200
spring.data.elasticsearch.repositories.enabled=true
spring.elasticsearch.jest.uris=http://localhost:9200
spring.elasticsearch.jest.connection-timeout=3s
spring.elasticsearch.rest.uris=http://localhost:9200
spring.data.elasticsearch.cluster-name=elasticsearch

@Configuration
@EnableElasticsearchRepositories(basePackages = 
"com.example.elasticsearch.repository")
public class ElasticSearchConfiguration {
 @Bean
 public Client client() throws UnknownHostException {
    Settings settings = Settings.builder()
            .put("client.transport.sniff", true)
            .put("cluster.name", "elasticsearch").build();
    @SuppressWarnings("resource")
    TransportClient client = new PreBuiltTransportClient(settings)
            .addTransportAddress(new 
 TransportAddress(InetAddress.getByName("127.0.0.1"), 9200));

    return client;
}

@Bean
public ElasticsearchOperations elasticsearchTemplate() throws 
UnknownHostException {
    return new ElasticsearchTemplate(client());
   }
}

1 个答案:

答案 0 :(得分:0)

我认为您误会了使用port = 9200并尝试使用port = 9300。从您的应用程序连接到Elastic Search服务器后,将使用端口号9300,而不是9200。