5

Hi I am trying to connect my ElasticSearch Client to my localhost and trying to get the indices from there.

import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;
import org.elasticsearch.client.transport.*;
import org.elasticsearch.common.transport.*;
import java.io.IOException;
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
public class ESClient
{
    public static void search()throws IOException
    {
        Node node;
        node = nodeBuilder().clusterName("elasticsearch").node();
        Client client;
        client= new TransportClient()
                .addTransportAddress(new InetSocketTransportAddress("localhost", 9200));
        GetResponse response;
        response= client.prepareGet("twitter", "tweet", "1").execute() .actionGet();
        System.out.println(response.toString());

    }
    public static void main(String args[])throws IOException
    {
        search();

    }

}

I have created the indices using the terminal.

curl -XPUT 'http://localhost:9200/twitter/' curl -XPUT 'http://localhost:9200/twitter/_mapping/tweet' -d ' {
"tweet" : { "properties" : {
"message" : {"type" : "string", "store" : true } }
} } '

When I am executing it, the following error is thrown,

NFO: [Blackheath] failed to get node info for [#transport#-1][BLRMCB-C02L56J4DR53.local][inet[localhost/127.0.0.1:9200]], disconnecting... org.elasticsearch.transport.ReceiveTimeoutTransportException: [][inet[localhost/127.0.0.1:9200]][cluster:monitor/nodes/info] request_id [0] timed out after [5002ms] at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:366) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

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.get(AbstractClient.java:193) at org.elasticsearch.client.transport.TransportClient.get(TransportClient.java:384) at org.elasticsearch.action.get.GetRequestBuilder.doExecute(GetRequestBuilder.java:201) at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91) at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65) at ....ESClient.search(ESClient.java:30) at ....ESClient.main(ESClient.java:36) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

What is the problem, can anyone tell me?

1 Answer 1

1

I got this error when I switched from using an ElasticSearchAdapter for queries to a SparkStreamingAdapter for the same queries. I had to change the port to 9300, and then this error did not appear.

This question/answer helped me figure this out: Why can't I connect to ElasticSearch through Java API?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.