No connection could be made because the target machine actively refused

I have an issue

I tried to use elasticsearch, but have an issue
Invalid NEST response built from a unsuccessful low level call on PUT: /mytweetindex/tweet/1
Audit trail of this API call:

  • [1] BadRequest: Node: http://127.0.0.1:9200/ Took: 00:00:01.0227803
    OriginalException: System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 192.168.100.34:9200
    at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
    at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
    --- End of inner exception stack trace ---
    at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
    at System.Net.HttpWebRequest.GetRequestStream()
    at Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData requestData) in C:\Projects\elastic\net-5\src\Elasticsearch.Net\Connection\HttpConnection.cs:line 149
    Request:
    <Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
    Response:
    <Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>

this is code
private static ElasticClient client;

	public void StartClient()
	{
		var node = new Uri("http://192.168.100.34:9200");
		var settings = new ConnectionSettings(node);
		client = new ElasticClient(settings);


		var tweet = new Tweet
		{
			Id = 1,
			User = "kimchy",
			PostDate = new DateTime(2009, 11, 15),
			Message = "Trying out NEST, so far so good?"
		};

		var response = client.Index(tweet, idx => idx.Index("mytweetindex"));
	}
}`

I disable fairwall and windows defender
Also I tried open app as administrator

Is your Elasticsearch instance running and configured without any security?

What happens when you navigate to localhost:9200 in your browser?

Yes, exactly, I forgot about run elasticsearch instance
So, right now I trying to start it, but it a bit difficult. I tried to start but file, but it closed in a moment.
Maybe you can help me with run elasticsearch bat file?

Execute it from commandline so you can see the message it gives.

Open a command prompt in administrator mode, change your directory to wherever the launch script is and execute it. Does it log an error message?

I got the similar error , eventhough the elastic search is running well in our product box. please help.

"Invalid NEST response built from a unsuccessful low level call on GET: /apifrecord360%2A/_settings\r\n# Audit trail of this API call:\r\n - [1] BadResponse: Node: http://XXXXXXX.cloudapp.azure.com:9200/ Took: 00:00:21.4285309\r\n# OriginalException: System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond xx.xxx.xx.xx:8080\r\n at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)\r\n at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)\r\n --- End of inner exception stack trace ---\r\n at System.Net.HttpWebRequest.GetResponse()\r\n at Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData requestData) in C:\Projects\elastic\net-5\src\Elasticsearch.Net\Connection\HttpConnection.cs:line 164\r\n# Request:\r\n<Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>\r\n# Response:\r\n<Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>\r\n"

the following is my connectsettings:

node = new Uri((Properties.Settings.Default.URI));
var settings = new ConnectionSettings(node).RequestTimeout(TimeSpan.FromMinutes(2));
client = new ElasticClient(settings);

So you've switched to pointing it towards your remote Elastic rather than local?

Is it possible there are some firewall rules you aren't accounting for? This seems like it could be a networking issue moreso than a problem with Elasticsearch configuration.

I would see if you can resolve the issue by making sure your network rules are configured properly and just hitting the node with a GET on the root via some API testing tool like postman. Make sure you include whatever auth you need in the request.

GET  HTTP/1.1
Host: {{ElasticUrl}}
Content-Type: application/json
Cache-Control: no-cache

Where {{ElasticUrl}} is pointing to your environment. Add basic auth if you've configured it in such a way.

Once you see a response similar to this, go back to configuring your NEST client:

{
  "name": "xxxxx",
  "cluster_name": "xxxxx",
  "cluster_uuid": "xxxxx",
  "version": {
    "number": "5.3.1",
    "build_hash": "5f9cf58",
    "build_date": "2017-04-17T15:52:53.846Z",
    "build_snapshot": false,
    "lucene_version": "6.4.2"
  },
  "tagline": "You Know, for Search"
}

thank you for your quick response!

when i run {{ElasticUrl}} , it turned the small jason file, the pattern is similar as you shown me.

debugging the code, the error is pointing to the line " var result = client.GetIndexSettings(request);"

the following is the code

var request = new GetIndexSettingsRequest(pattern + "*", null); //pattern is the name of index

///if we find any matching indexes, keep going

if (request != null)

{

     ///Pulls all settings for all the indexes that match the pattern.  
     var result = client.GetIndexSettings(request);
     ...

}

is that limitation for GetIndexSettings in 5.X version? wierd, it works in my local, but not in prod environment. both using 5.2.2 version now

thanks,

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