我正在尝试检索、update和从Amazon中删除数据。为了从获取数据,我使用了官方的Java of www.elastic.co,但是我不知道我的Java代码有什么问题。
我也不是AWS方面的专家。但是当我在浏览器中打开search-testing-xxxxxxxxxxxxx.ap-xxxxxxx-1.es.amazonaws.com url时,它会提供响应。同样的url也适用于PHP中的所有操作。
如果有另一个库连接Amazon,请提供示例链接。
源代码
import java.net.InetAddress;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
public class ElasticSearchExample {
public static void main(String[] args) throws Exception{
Settings settings = Settings.settingsBuilder()
.put("cluster.name", "34xxxxxxx:testing")
.put("http.enabled", true).build();
Client client = TransportClient
.builder()
.settings(settings)
.build()
.addTransportAddress(
new InetSocketTransportAddress(
InetAddress
.getByName("search-testing-xxxxxxxxxxxxx.ap-xxxxxxx-1.es.amazonaws.com"),
80));
GetResponse response = client.prepareGet("inventory", "parent", "7874").get();
System.out.println(response);
client.close();
}
}输出
Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{xx.xxx.xxx.x}{search-testing-xxxxxxxxxxxxx.ap-xxxxxxx-1.es.amazonaws.com/xx.xxx.xxx.x:80}]]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:290)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:207)
at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55)
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:283)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:347)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:85)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:59)
at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:67)
at ElasticSearchExample.main(ElasticSearchExample.java:28)发布于 2016-01-12 07:38:57
Amazon服务只在HTTP上工作,您正试图通过传输客户端连接到它,该客户端在TCP上工作。
您可以使用任何其他Java客户端库,如Apache客户机或更高级别的Spring的RestTemplate,如下所示
// create the REST template
RestTemplate rest = new RestTemplate()
// define URL to fetch
String url = "http://search-testing-xxxxxxxxxxxxx.ap-xxxxxxx-1.es.amazonaws.com/inventory/parent/7874";
// make the request
ResponseEntity<String> resp = rest.exchange(url, HttpMethod.GET, null, String.class)
// retrieve the JSON response
String body = resp.getBody();https://stackoverflow.com/questions/34737560
复制相似问题