使用弹性的java客户端怎么说aws弹性搜索服务? [英] How to talk to aws elasticsearch service using elastic java client?

查看:261
本文介绍了使用弹性的java客户端怎么说aws弹性搜索服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 AWS弹性搜索服务(非EC2)设置了弹性搜索服务器。它给了我一个端点 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"
}

问题是如何通过弹性搜索java客户端没有端口号?我得到的示例代码是

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));

如果我使用这个代码,只是用我的端点替换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.

编辑
我终于决定使用 Jest ,第三方REST客户端。但是布鲁克斯下面回答的也是非常有帮助的 - AWS使用端口80作为http和443用于https。阻止我的是防火墙我猜。

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服务文档明确说:

该服务支持端口80上的HTTP,但不支持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,_ type:myType,_ id:SOME_ID _#,_ version:1,created:true}

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

入住基巴那,你会看到它在那里。

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

那么在你的代码中,应该是:

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调用,而不是使用JERSEY。

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弹性搜索服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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