如何使用弹性Java客户端交谈AWS elasticsearch服务? [英] How to talk to aws elasticsearch service using elastic java client?

查看:300
本文介绍了如何使用弹性Java客户端交谈AWS elasticsearch服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了使用 AWS elasticsearch服务(不EC2)一elasticsearch服务器。它给了我一个端点的https://xxx-xxxxxxxx.us-west-2 .es.amazonaws.com / ,如果​​我点击这个端点(注意,没有指定的端口),我可以得到预期的

I have set up a elasticsearch server using AWS elasticsearch service (Not EC2). It gave me an endpoint https://xxx-xxxxxxxx.us-west-2.es.amazonaws.com/ and if I click this endpoint(Note that there is no port specified) I can get the expected

{
  status: 200,
  name: "Mastermind",
  cluster_name: "xxxx",
  version: {
    number: "1.5.2",
    build_hash: "yyyyyy",
    build_timestamp: "2015-04-27T09:21:06Z",
    build_snapshot: false,
    lucene_version: "4.10.4"
  },
  tagline: "You Know, for Search"
}

现在的问题是我怎么得到这个通过elasticsearch Java客户端没有端口号?样品code我得到的是

The question is how do I get this through the elasticsearch java client without a port number? The sample code I get is

Client client = TransportClient.builder().build()
    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300));

如果我用这个code和刚刚替换为host1我的终点,我会得到NoNodeAvailableException

If I use this code and just replace "host1" with my endpoint, I'll get "NoNodeAvailableException"

PS: 我使用的是Java客户端版本为2.0.0。

ps: The java client version I'm using is 2.0.0.

修改 我终于决定去与玩笑,第三方REST客户端。但是,下面布鲁克斯回答也非常有帮助 - AWS不要使用端口80用于HTTP和HTTPS的443。该受体阻滞剂对我来说是防火墙,我猜。

Edit I finally decided to go with Jest, a 3rd party REST client. But what Brooks answered below is also very helpful - AWS do use port 80 for http and 443 for https. The blocker for me was the firewall I guess.

EDIT2 在AWS ES服务文档明确地说:
服务支持HTTP端口80上,但不支持TCP传输。

Edit2 The AWS ES service documentation explicitly says:
The service supports HTTP on port 80, but does not support TCP transport.

推荐答案

不管你信不信,AWS不使用9200和9300无法启动Elasticsearch它通过普通的旧端口80推出。

Believe it or not, AWS doesn't launch Elasticsearch using 9200 and 9300. It's launched via plain old port 80.

所以,为了证明,试试这个......

So, to demonstrate, try this...

curl -XPOST "http://xxx-xxxxxxxx.us-west-2.es.amazonaws.com:80/myIndex/myType" -d '["name":"Edmond"}'

curl -XPOST "https://xxx-xxxxxxxx.us-west-2.es.amazonaws.com:443/myIndex/myType" -d '["name":"Edmond"}'

这应该回应:     {_index:myIndex,_类型:的myType,_ ID:SOME_ID _#,_版本:1,创造:真}

It should respond with: {"_index":"myIndex","_type":"myType","_id":"SOME_ID_#","_version":1,"created":true}

检查Kibana,你会发现它的存在。

Check in Kibana and you'll see it's there.

因此​​,然后在code,它应该是:

So, then in your code, it should be:

Client client = TransportClient.builder().build()
    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("xxx-xxxxxxxx.us-west-2.es.amazonaws.com"), 80));

不幸的是,我不副手知道如何传送通过SSL / HTTPS使用传输客户端加密。你可以尝试使用常规REST调用,而不是用球衣。

Unfortunately, I don't off-hand know how to transmit encrypted via SSL/HTTPS using the transport client. You could try using regular REST calls instead using JERSEY.

最后,确保你的Elasticsearch访问策略配置是否正确。线沿线的东西:

Finally, make sure your Elasticsearch access policy is configured properly. Something along the lines of:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "es:*",
      "Resource": "arn:aws:es:us-east-1:yyyyyyy:domain/myDomain/*"
    },
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "es:*",
      "Resource": "arn:aws:es:us-east-1:yyyyyyyyy:domain/myDomain"
    }
  ]
}

注意:上面的准入政策是完全敞开的,因此不建议进行任何远程接近生产。只要你知道......

NOTE: The above access policy is completely wide open and is not recommended for anything remotely close to production. Just so you know....

这篇关于如何使用弹性Java客户端交谈AWS elasticsearch服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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