使用Java Client和X-Pack / HTTPS连接到ElasticSearch Cloud 5.x [英] Connecting to ElasticSearch Cloud 5.x with Java Client and X-Pack/HTTPS

查看:1499
本文介绍了使用Java Client和X-Pack / HTTPS连接到ElasticSearch Cloud 5.x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用X-Pack通过HTTPS连接到ElasticSearch吗?随着切换使用证书,自己的连接方式不再工作。我没有使用证书的问题,但我需要知道在哪里得到一个或将密钥上传到云实例,但我无法在任何地方找到信息。我也没有在论坛或IRC的任何人的回答。



有没有人成功完成这个?启动5.x实例时不再有警告,所以我认为这是可能的,但是我根本无法弄清楚如何做到这一点。我也被告知,我不能再启动一个2.4.1的实例,只有2.4.2是可用的(到目前为止太不稳定),所以我有点不能启动一个可用的实例。






更新



我被告知,由于使用公共CA,因此不需要任何证书。但是,我仍然无法弄清楚如何连接到5.1.1实例。

 设置设置= Settings.builder ()
.put(transport.ping_schedule,5s)
.put(cluster.name,< cluster_id>)
.put(xpack.security
.put(xpack.security.user,elastic:< password_from_cluster_creation>)
.build();

String hostname =< cluster_id> .us-east-1.aws.found.io;
TransportClient client = new PreBuiltXPackTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostname),9343));

我在这里做错什么?我收到一个错误,表示节点不可用。

 线程main中的异常NoNodeAvailableException [没有配置的节点可用:[{#transport#-1} {xlhZqKBCQniYrN4OWzByFQ} {< cluster_id> .us-east-1.aws.found.io} {< id_address>:9343}] 

我还尝试创建一个具有transport_client角色的用户,但仍然是同样的错误。






更新2



我从这里尝试了示例代码,但仍然无法使用。



https://github.com/elastic/found-shield-example/blob/master/src/main/java/org/elasticsearch/cloud/transport/example/TransportExample.java



这是一个可以测试的实例。稍后我会解决问题后,我会摧毁它。






更新3



我想出了这个问题,摧毁了测试集群。找到下面的解决方案。

解决方案

经过与ES论坛上的人的讨论,我终于得到了工作。当您遇到连接问题时,以下是一些提示:



1)您可能没有将其添加到标题中,因为文档中没有提及

  .put(request.headers.X-Found-Cluster,clusterName)
/ pre>

2)如果仍然无法使用,请使用此处的示例代码验证您的主机名是否正确,并且您具有正确的凭据



https://github.com/elastic / found-shield-example#running



3)如果您尝试在Eclipse中运行示例代码,请在您之前替换$ {cluster.name}运行它或它将无法工作。



希望这个帮助可以节省人们一段时间试图找出连接问题。连接到ES 5.x大约是2.x.问题是文档不清楚,没有链接到示例客户端。


Is it possible to connect to ElasticSearch via HTTPS using X-Pack? With the switch to use certificate, the own way of connecting is no longer work. I have no problem with using certificate, but I need to know where to get one or upload the key to the cloud instance, but I cannot find information anywhere. I'm also getting no answer from anyone in the forum or IRC.

Has anyone successfully done this? There is no longer a warning when launching a 5.x instance so I assumed this is possible, but I just can't figure out how to do it. I was also told that I can no longer launch a 2.4.1 instance and only 2.4.2 is available (too unstable so far) so I'm kinda stuck not being able to launch a usable instance.


Update

I was told that no certificate is required since public CA is being used. However, I'm still not able to figure out how to connect to 5.1.1 instance.

Settings settings = Settings.builder()
            .put("transport.ping_schedule", "5s")
            .put("cluster.name", "<cluster_id>")
            .put("xpack.security.transport.ssl.enabled", "true")
            .put("xpack.security.user", "elastic:<password_from_cluster_creation>")
            .build();

    String hostname = "<cluster_id>.us-east-1.aws.found.io";
    TransportClient client = new PreBuiltXPackTransportClient(settings)
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostname), 9343));

What am I doing wrong here? I'm getting an error saying node is not available.

Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{xlhZqKBCQniYrN4OWzByFQ}{<cluster_id>.us-east-1.aws.found.io}{<id_address>:9343}]]

I also tried creating a user with transport_client role, but still the same error.


Update 2

I tried the sample code from here and it still doesn't work.

https://github.com/elastic/found-shield-example/blob/master/src/main/java/org/elasticsearch/cloud/transport/example/TransportExample.java

Here's an instance you can test with. I will destroy it later after I have figured out the issue.


Update 3

I figured out the issue and destroyed the test cluster. Find the solution below.

解决方案

After some discussion with people on ES forum, I got it working finally. Here are some tips when you run into an issue with connection:

1) You probably didn't add this in the header since it's not mentioned in the documentation

.put("request.headers.X-Found-Cluster", clusterName)

2) If that still doesn't work, use the sample code from here to verify that you hostname is correct and you have the correct credential

https://github.com/elastic/found-shield-example#running

3) If you are trying to run the sample code within Eclipse, replace ${cluster.name} before you run it or it won't work.

Hope this help save people some time trying to figure out connection issue. Connecting to ES 5.x is about as easy as 2.x. The problem is that the documentation is not clear and there is no link to sample client.

这篇关于使用Java Client和X-Pack / HTTPS连接到ElasticSearch Cloud 5.x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆