1

I'm trying to retrieve, update and delete data from Amazon Elasticsearch. To fetch the data from Amazon Elasticsearch Service I used official Java API of www.elastic.co but I couldn't figure out whats wrong in my Java code.

Also I'm not expert on AWS. But when I open search-testing-xxxxxxxxxxxxx.ap-xxxxxxx-1.es.amazonaws.com url in browser it provides response. Also same url works for all operation in PHP.

If there is another library to connect Amazon Elasticsearch, please provide link with example.

Source code

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

Output

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)

1 Answer 1

2

The Amazon Elasticsearch service works exclusively over HTTP and you're trying to connect to it via the Transport client which works over TCP.

You can use any other Java HTTP client library, such as the Apache HTTP client or the higher-level Spring's RestTemplate, as shown below

// 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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.