Exception in thread "main" java.net.ConnectException: Timeout connecting to [localhost:9200]

Exception in thread "main" java.net.ConnectException: Timeout connecting to [localhost:9200]
	at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:804)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:225)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:212)
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1433)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1403)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1373)
	at org.elasticsearch.client.RestHighLevelClient.get(RestHighLevelClient.java:699)
	at com.es.App.main(App.java:18)
Caused by: java.net.ConnectException: Timeout connecting to [localhost:9200]
	at org.apache.http.nio.pool.RouteSpecificPool.timeout(RouteSpecificPool.java:169)
	at org.apache.http.nio.pool.AbstractNIOConnPool.requestTimeout(AbstractNIOConnPool.java:628)
	at org.apache.http.nio.pool.AbstractNIOConnPool$InternalSessionRequestCallback.timeout(AbstractNIOConnPool.java:894)

And the code i am using is:

RestHighLevelClient client = new RestHighLevelClient(
    	        RestClient.builder(
    	                new HttpHost("localhost", 9200, "http")));
    	GetRequest getRequest = new GetRequest("index_name" , "1");
    	GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT);

What is the output of:

curl -XGET http://localhost:9200/index_name/_search
{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "child \"method\" fails because [\"method\" must be one of [HEAD, GET, POST, PUT, DELETE]]",
  "validation": {
    "source": "query",
    "keys": [
      "method"
    ]
  }
}

Could you do a screenshot ?

This is the screenshot of the result when the command is executed in the command prompt and i am trying to connect to my aws instance of elastic search.

Thank you @dadoonet . I found that the port 9200 is not open in the elastic search server. I tried same query by opening port 9200. Now, it's working fine.

So I don't understand where this message was coming from:

{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "child \"method\" fails because [\"method\" must be one of [HEAD, GET, POST, PUT, DELETE]]",
  "validation": {
    "source": "query",
    "keys": [
      "method"
    ]
  }
}

BTW the fact that you hide the IP address or the URL makes me think that you are exposing your cluster on internet. Are you doing that?
If so, please, don't do it. At least without any security layer.

You can also look at cloud.elastic.co which contains everything you need as a service.

Above message is coming from console because i tried to execute the command from the devtools console mistakenly as i am new to elastic search. Thank you for your valuable information regarding security.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.