Java 如何连接到 AWS Elasticsearch?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33412635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:39:19  来源:igfitidea点击:

How to connect to AWS Elasticsearch?

javaamazon-web-serviceselasticsearchamazon-elasticsearch

提问by Fabian Lurz

I'm trying to connect to AWS Elasticsearch but I always get the following error:

我正在尝试连接到 AWS Elasticsearch,但总是收到以下错误:

Exception in thread "main" org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:278)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:197)
at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)
at org.elasticsearch.client.support.AbstractClient.index(AbstractClient.java:98)
at org.elasticsearch.client.transport.TransportClient.index(TransportClient.java:334)
at org.elasticsearch.action.index.IndexRequestBuilder.doExecute(IndexRequestBuilder.java:313)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65)
at com.c_backendcrawler.utility.ElasticSearch.uploadObject(ElasticSearch.java:25)
at com.c_backendcrawler.Start.main(Start.java:34)

My code is following:

我的代码如下:

 //Create Client
    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "zencubes-search").put("node.name","Darkhawk").build();
    TransportClient transportClient = new TransportClient(settings);
    transportClient.addTransportAddress(new InetSocketTransportAddress(
            "x.x.x.x",9300));
    return transportClient;

Output from AWS Elasticsearch:

AWS Elasticsearch 的输出:

    {
status: 200,
name: "Darkhawk",
cluster_name: "817880037706:zencubes-search",
version: {
number: "1.5.2",
build_hash: "62ff9868b4c8a0c45860bebb259e21980778ab1c",
build_timestamp: "2015-04-27T09:21:06Z",
build_snapshot: false,
lucene_version: "4.10.4"
},
tagline: "You Know, for Search"
}

I tried to curl (https://search-zencubes-search-xxxxxxxx.eu-west-1.es.amazonaws.com/) and it works - but not on port 9300. What am I doing wrong here?

我试图卷曲(https://search-zencubes-search-xxxxxxxx.eu-west-1.es.amazonaws.com/)并且它有效 - 但不在端口 9300 上。我在这里做错了什么?

采纳答案by John Russell

The native transport protocol is not support using AWS Managed ElasticSearch and is only available over the REST endpoint. Consider switching your client to consume the REST endpoint, such as https://github.com/searchbox-io/Jest.

本机传输协议不支持使用 AWS Managed ElasticSearch,并且只能通过 REST 端点使用。考虑切换客户端以使用 REST 端点,例如https://github.com/searchbox-io/Jest

Source: https://forums.aws.amazon.com/thread.jspa?messageID=681938

来源:https: //forums.aws.amazon.com/thread.jspa?messageID=681938

回答by Ivan Krumov

As John Russell said above, you need to use a REST client to communicate with your AWS Elastic cluster.

正如 John Russell 上面所说,您需要使用 REST 客户端与您的 AWS Elastic 集群进行通信。

Elastic recently released the first RC version of its own Java REST client, so this is an option now as well.

Elastic 最近发布了它自己的 Java REST 客户端的第一个 RC 版本,所以现在这也是一个选项。

Client Docs: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html

客户端文档:https: //www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html

Maven Repo: http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.elasticsearch.client%22%20AND%20a%3A%22rest%22

Maven 仓库:http: //search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.elasticsearch.client%22%20AND%20a%3A%22rest%22

回答by H6.

Since the Elasticsearch Java SDK version 5.6there is a REST Clientavailable. This allows you to connect to Elasticsearch Service on AWS.

从 Elasticsearch Java SDK 版本 5.6 开始,有一个REST 客户端可用。这允许您连接到 AWS 上的 Elasticsearch Service。

Currently Elasticsearch Service allows installations up to version 5.5, but you can use the 5.6 Java SDK against a 5.5 cluster with minor limitations.

目前 Elasticsearch Service 允许安装到 5.5 版本,但您可以对 5.5 集群使用 5.6 Java SDK,但有一些限制。

Note: When initializing the RestClientyou should use the port 80or 443respectively instead of the 9200. E.g.

注意:在初始化 时,RestClient您应该分别使用端口80443代替9200. 例如

RestClient restClient = RestClient.builder(
    new HttpHost("search-test-elasti-xxxx-xxxxx.us-east-1.es.amazonaws.com", 80, "http")).build();
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClient); 
// [...]