0

我是弹性搜索的新手。我已经创建了示例项目来将数据索引到弹性云中。并尝试使用我的 c# 代码来检索它。在我的本地电脑中,我的弹性搜索 api 工作正常,但在托管时它给了我“试图以访问权限禁止的方式访问套接字”错误。

如何解决此错误?

我的示例代码到 c#

    var uri = new Uri("https://elastic:passowrd@cloud url");
    var settings = new ConnectionSettings(uri).DisableDirectStreaming();
    var client = new ElasticClient(settings);

    var response1 = client.ClusterHealth();

    _logger.Error("debug info");
    if (response1.DebugInformation != null)
        _logger.Error(response1.DebugInformation    );

完整的错误消息显示如下:-

Invalid NEST response built from a unsuccessful low level call on GET: /_cluster/health
# Audit trail of this API call:
- [1] BadRequest: Node: https://elastic:pt8wcFiAaGdjrz1sJKSI5FfW@4b9793e5c28e4c42ba30026f534b8593.europe-west1.gcp.cloud.es.io:9243/ Took: 00:00:00.0553689
# OriginalException: System.Net.Http.HttpRequestException: An attempt was made to access a socket in a way forbidden by its access permissions ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   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:
4

1 回答 1

0

我遇到了类似的错误。此错误是因为您应该允许端口 9200-9300 入站的托管服务器。该错误指定尝试访问未授予权限的端口

于 2019-04-12T09:46:04.600 回答