无法在Elasticsearch中执行搜索,错误“嗅探群集状态失败。”

时间:2018-10-03 12:32:44

标签: elasticsearch nest

我一直在使用Elasticsearch遇到一个奇怪的问题,其中只有Search API失败,并显示消息“嗅探群集状态失败”。其他API,例如Bulk和CreateIndex等也可以正常工作。该代码也可以在其他系统中使用,因此我可以肯定,这仅是本地系统的问题。详细信息如下:

我正在使用SniffingConnectionPool创建一个ElasticClient。 Elastic集群是在另一台机器上设置的,当我在运行代码的同一台机器上使用弹性实例设置时,一切都会再次正常运行。

这是我在返回的响应中找到的各种异常对象的堆栈跟踪:

Unsuccessful low level call on GET: /_nodes/http,settings?timeout=2s&flat_settings=true
# Audit trail of this API call:
# 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 127.0.0.1:8888
   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.Request[TResponse](RequestData requestData)
# 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.>


No connection could be made because the target machine actively refused it 127.0.0.1:8888


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)

请提出至少一些方法的解决方案,以便对其进行进一步调试并找到解决问题的方法。

响应GET / _nodes / http,settings?timeout = 2s&flat_settings = true HTTP / 1.1

{
    "_nodes": {
        "total": 2,
        "successful": 2,
        "failed": 0
    },
    "cluster_name": "elasticsearch_marvel",
    "nodes": {
        "i6Nvug3zQ5Wv5Kj-wiPCdg": {
            "name": "Wolverine",
            "transport_address": "10.10.10.10:9301",
            "host": "10.10.10.10",
            "ip": "10.10.10.10",
            "version": "6.2.4",
            "build_hash": "ccec39f",
            "roles": ["master", "data", "ingest"],
            "settings": {
                "client.type": "node",
                "cluster.name": "elasticsearch_marvel",
                "discovery.zen.minimum_master_nodes": "1",
                "discovery.zen.ping.unicast.hosts": "10.10.10.10:9300",
                "http.max_content_length": "1000mb",
                "http.port": "9201",
                "http.type.default": "netty4",
                "network.host": "10.10.10.10",
                "node.data": "true",
                "node.master": "true",
                "node.name": "Wolverine",
                "path.home": "C:\\Elasticsearch\\elasticsearch-6.2.4 - Node1",
                "path.logs": "C:\\Elasticsearch\\elasticsearch-6.2.4 - Node1\\logs",
                "transport.bind_host": "10.10.10.10",
                "transport.tcp.port": "9301",
                "transport.type.default": "netty4"
            },
            "http": {
                "bound_address": ["10.10.10.10:9201"],
                "publish_address": "10.10.10.10:9201",
                "max_content_length_in_bytes": 1048576000
            }
        },
        "Q-apZOAdTwuvR6D5kfGF2g": {
            "name": "Wolverine",
            "transport_address": "10.10.10.10:9300",
            "host": "10.10.10.10",
            "ip": "10.10.10.10",
            "version": "6.2.4",
            "build_hash": "ccec39f",
            "roles": ["master", "data", "ingest"],
            "settings": {
                "client.type": "node",
                "cluster.name": "elasticsearch_marvel",
                "discovery.zen.minimum_master_nodes": "1",
                "discovery.zen.ping.unicast.hosts": "10.10.10.10:9301",
                "http.max_content_length": "1000mb",
                "http.port": "9200",
                "http.type.default": "netty4",
                "network.host": "10.10.10.10",
                "node.data": "true",
                "node.master": "true",
                "node.name": "Wolverine",
                "path.home": "C:\\Elasticsearch\\elasticsearch-6.2.4",
                "path.logs": "C:\\Elasticsearch\\elasticsearch-6.2.4\\logs",
                "transport.bind_host": "10.10.10.10",
                "transport.tcp.port": "9300",
                "transport.type.default": "netty4"
            },
            "http": {
                "bound_address": ["10.10.10.10:9200"],
                "publish_address": "10.10.10.10:9200",
                "max_content_length_in_bytes": 1048576000
            }
        }
    }
}

两个节点对以下请求的响应:

  1. 节点1:POST / contentindex_636723112889619049 / _search?scroll = 30s HTTP / 1.1
  2. 节点2:POST / contentindex_636723112889619049 / _search?scroll = 30s HTTP / 1.1

    {
    "_scroll_id": "DnF1ZXJ5VGhlbkZldGNoBQAAAAAAAAAvFmk2TnZ1ZzN6UTVXdjVLai13aVBDZGcAAAAAAAAALRZRLWFwWk9BZFR3dXZSNkQ1a2ZHRjJnAAAAAAAAADEWaTZOdnVnM3pRNVd2NUtqLXdpUENkZwAAAAAAAAAuFlEtYXBaT0FkVHd1dlI2RDVrZkdGMmcAAAAAAAAAMBZpNk52dWczelE1V3Y1S2otd2lQQ2Rn",
    "took": 1986,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 1.683245,
        "hits": [{
            "_index": "50000_default_contentindex_636723112889619049",
            "_type": "_doc",
            "_id": "2492241",
            "_score": 1.683245,
            "_source": {
                "module_id": 528,
                "content_id": 2492241,
                "module_type_id": 2,
                "level_id": 330
            }
        }]
    }
    

    }

现在您可以看到服务器返回的HTTP响应符合预期,但是我从NEST获得的响应有错误,即

<InnerException>
    <ExceptionType>Elasticsearch.Net.PipelineException, Elasticsearch.Net, Version=6.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d</ExceptionType>
    <Message>An error occurred trying to read the response from the specified node.</Message>
    <Source>Elasticsearch.Net</Source>
    <StackTrace>   at Elasticsearch.Net.RequestPipeline.Sniff()</StackTrace>
</InnerException>

0 个答案:

没有答案