如何连接到AWS Elasticsearch?

时间:2015-10-29 11:11:39

标签: java amazon-web-services elasticsearch amazon-elasticsearch

我尝试连接到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)

我的代码如下:

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

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"
}

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

4 个答案:

答案 0 :(得分:14)

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

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

答案 1 :(得分:4)

Since the Elasticsearch Java SDK version 5.6有一个REST Client可用。这允许您连接到AWS上的Elasticsearch Service。

目前,Elasticsearch Service允许安装最高版本5.5,但您可以将5.6 Java SDK用于5.5集群,但有一些小的限制。

注意:初始化<a href="#" id="rkBtn" class="btn disabled"Next Step</a> 时,应分别使用端口<a href="#" id="rkBtn" class="btn disabled">Next Step</a> RestClient而不是80。 E.g。

443

答案 2 :(得分:2)

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

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

客户文档: 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

答案 3 :(得分:1)

如何获取AWS ES URL

转到Elasticsearch Domain控制台并在“概述”选项卡中获取端点。

要使用的端口是443。

enter image description here

确保已配置访问控制。

enter image description here


仅供参考

创建Elasticsearch索引

curl -v -XPUT "${ES_ENDPOINT}/article/" -H 'Content-Type: application/json' -d '{
    "settings" : {
        "index" : {
            "number_of_shards" : 1,
            "number_of_replicas" : 0
        }
    }
}'