如何连接到 AWS Elasticsearch?
How to connect to AWS 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 上无效。我在这里做错了什么?
本机传输协议不支持使用 AWS Managed ElasticSearch,并且只能通过 REST 端点使用。考虑切换您的客户端以使用 REST 端点,例如 https://github.com/searchbox-io/Jest.
来源:https://forums.aws.amazon.com/thread.jspa?messageID=681938
正如 John Russell 上面所说,您需要使用 REST 客户端与您的 AWS Elastic 集群通信。
Elastic 最近发布了它自己的 Java REST 客户端的第一个 RC 版本,所以现在这也是一个选项。
客户文档:
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html
Since the Elasticsearch Java SDK version 5.6 there is a REST Client 可用。这允许您连接到 AWS 上的 Elasticsearch 服务。
目前 Elasticsearch Service 允许安装最高版本 5.5,但您可以针对 5.5 集群使用 5.6 Java SDK,但有一些小限制。
注意: 初始化RestClient
时你应该分别使用端口80
或443
而不是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);
// [...]
如何获取 AWS ES URL
转到 Elasticsearch 域控制台并在概览选项卡中获取端点。
要使用的端口是 443。
确保已配置访问控制。
仅供参考
创建 Elasticsearch 索引
curl -v -XPUT "${ES_ENDPOINT}/article/" -H 'Content-Type: application/json' -d '{
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 0
}
}
}'
我正在尝试连接到 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 上无效。我在这里做错了什么?
本机传输协议不支持使用 AWS Managed ElasticSearch,并且只能通过 REST 端点使用。考虑切换您的客户端以使用 REST 端点,例如 https://github.com/searchbox-io/Jest.
来源:https://forums.aws.amazon.com/thread.jspa?messageID=681938
正如 John Russell 上面所说,您需要使用 REST 客户端与您的 AWS Elastic 集群通信。
Elastic 最近发布了它自己的 Java REST 客户端的第一个 RC 版本,所以现在这也是一个选项。
客户文档: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html
Since the Elasticsearch Java SDK version 5.6 there is a REST Client 可用。这允许您连接到 AWS 上的 Elasticsearch 服务。
目前 Elasticsearch Service 允许安装最高版本 5.5,但您可以针对 5.5 集群使用 5.6 Java SDK,但有一些小限制。
注意: 初始化RestClient
时你应该分别使用端口80
或443
而不是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);
// [...]
如何获取 AWS ES URL
转到 Elasticsearch 域控制台并在概览选项卡中获取端点。
要使用的端口是 443。
确保已配置访问控制。
仅供参考
创建 Elasticsearch 索引
curl -v -XPUT "${ES_ENDPOINT}/article/" -H 'Content-Type: application/json' -d '{
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 0
}
}
}'