Elasticsearch-net: Cannot Connect to Elasticsearch 6.3 From NEST

Created on 6 Aug 2018  路  3Comments  路  Source: elastic/elasticsearch-net

NEST version 6.2
ElasticSearch version 6.3.2

i have Docker Dev Image and i can access it and insert in the Index by Low level library, but i can not do the same with NEST , below is the code

the error i get "
Invalid NEST response built from a unsuccessful low level call on PUT: /people/person/2

Audit trail of this API call:

  • [1] SniffOnStartup: Took: 00:00:00.3109366
  • [2] SniffSuccess: Node: http://127.0.0.1:9200/ Took: 00:00:00.3070011
  • [3] PingFailure: Node: http://172.17.0.2:9200/ Exception: PipelineException Took: 00:00:02.0349983
  • [4] SniffOnFail: Took: 00:00:21.0087015
  • [5] SniffFailure: Node: http://172.17.0.2:9200/ Exception: PipelineException Took: 00:00:21.0067095

    OriginalException: Elasticsearch.Net.ElasticsearchClientException: Failed sniffing cluster state.. Call: unknown resource ---> Elasticsearch.Net.PipelineException: Failed sniffing cluster state. ---> Elasticsearch.Net.PipelineException: An error occurred trying to read the response from the specified node. ---> 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 172.17.0.2: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.GetResponse()
    at Elasticsearch.Net.HttpConnection.RequestTResponse
    --- End of inner exception stack trace ---
    at Elasticsearch.Net.RequestPipeline.Sniff()
    --- End of inner exception stack trace ---
    at Elasticsearch.Net.RequestPipeline.Sniff()
    at Elasticsearch.Net.RequestPipeline.SniffOnConnectionFailure()
    at Elasticsearch.Net.Transport1.Ping(IRequestPipeline pipeline, Node node) at Elasticsearch.Net.Transport1.RequestTResponse
    --- End of inner exception stack trace ---

    Audit exception in step 3 PingFailure:

Elasticsearch.Net.PipelineException: An error occurred trying to read the response from the specified node. ---> System.Net.WebException: The operation has timed out
at System.Net.HttpWebRequest.GetResponse()
at Elasticsearch.Net.HttpConnection.RequestTResponse
--- End of inner exception stack trace ---
at Elasticsearch.Net.RequestPipeline.Ping(Node node)

Audit exception in step 5 SniffFailure:

Elasticsearch.Net.PipelineException: An error occurred trying to read the response from the specified node. ---> 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 172.17.0.2: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.GetResponse()
at Elasticsearch.Net.HttpConnection.RequestTResponse
--- End of inner exception stack trace ---
at Elasticsearch.Net.RequestPipeline.Sniff()

Request:

Response:

"
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
class Program
{
static Uri[] uris = new[]
{
new Uri("http://127.0.0.1:9200")

        };
    static SniffingConnectionPool connectionPool = new SniffingConnectionPool(uris);
    static void Main(string[] args)
    {
        AddDocumentToIndex();
        Search1();

        Console.WriteLine("Hello World!");
    }
    static void AddDocumentToIndex()
    {
        var settings = new ConnectionSettings(connectionPool)
            .DefaultIndex("people");

        var client = new ElasticClient(settings);
        var person = new Person
        {
            Id = 2,
            FirstName = "Martijn2",
            LastName = "Laarman2"
        };

        var indexResponse = client.IndexDocument(person);

        //var asyncIndexResponse = await client.IndexDocumentAsync(person);
    }
    static void Search1()
    {
        var settings = new ConnectionSettings(connectionPool)
            .DefaultIndex("people");
        var client = new ElasticClient(settings);
        var searchResponse = client.Search<Person>(s => s
        .From(0)
        .Size(10)
        .Query(q => q
             .Match(m => m
                .Field(f => f.FirstName)
                .Query("Martijn")
                     )
                )
            );

        var people = searchResponse.Documents;
    }
}

Most helpful comment

It looks like the use of SniffingConnectionPool may be the cause of this. The seeded URI is http://127.0.0.1:9200, but after sniffing, the URI returned is 172.17.0.2:9200, which appears to be an address through which the node cannot be reached. What does

GET _nodes/http,settings

return for the HTTP publish_address?

All 3 comments

Very peculiar, you can sniff put not ping the node (HEAD on /).

What happens if you call .DisablePing() on ConnectionSettings ? Do you get a response back then?

It looks like the use of SniffingConnectionPool may be the cause of this. The seeded URI is http://127.0.0.1:9200, but after sniffing, the URI returned is 172.17.0.2:9200, which appears to be an address through which the node cannot be reached. What does

GET _nodes/http,settings

return for the HTTP publish_address?

yes , after i have replace sniffing with connection string with URL it works , thanks alot

Was this page helpful?
0 / 5 - 0 ratings