繁体   English   中英

使用 ZE6B391A8D2C4D458702A23A8B6 通过 spring 数据 elasticsearch 连接到 Elasticsearch 的远程实例

[英]Connect to remote instance of Elasticsearch through spring data elasticsearch using an URL

我是 ES 的新手,我在通过我的 java web 应用程序连接到外部实例 od ES 时遇到很多麻烦,假设我有以下客户端配置

@Configuration
@ComponentScan(basePackages = {"com.elasticsearchlogs.elasticsearchlogsbackend"})
public class Config extends AbstractElasticsearchConfiguration {

    @Value("${elasticsearch.url}")
    public String elasticsearchUrl;

    @Bean
    @Override
    public RestHighLevelClient elasticsearchClient() {
        final ClientConfiguration config = ClientConfiguration.builder()
                .connectedTo(elasticsearchUrl)
                .build();
        return RestClients.create(config).rest();
    }
}

当我使用elastichsearchUrl = "localhost:9200"进行一些测试时,一切都很好,但知道我应该连接到外部服务器中的 ES 实例,这是可以访问的,假设通过以下 url https://elasticinstance.com (是的,它使用 Https)。

问题是,如果像示例中那样放置 url,java 会抱怨,因为它要求提供端口号。 我真的不知道我要给它什么端口号,我尝试过使用 9300 和 9200,因为它们是 ES 中的默认端口,也使用 443,因为它是 Https 中的默认端口。

我应该怎么办? 我应该要求我的管理员给我一个端口号来连接吗? 还是我应该以任何特殊方式配置客户端?

我认为当您尝试使用 Https 连接到外部 Elasticsearch 服务器时,首先

  1. Go through, https://www.elastic.co/blog/configuring-ssl-tls-and-https-to-secure-elasticsearch-kibana-beats-and-logstash , this tells you how to Create SSL certificates and enable TLS对于 Elasticsearch。

  2. 然后您可以尝试使用 https://[ip/domainname:port].com 访问 Elasticsearch

或者首先验证当前设置是否一切正常

  1. 只需使用 HTTP 而不是 HTTPS 访问服务器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM