我是弹性搜索的新手。我已经创建了示例项目来将数据索引到弹性云中。并尝试使用我的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:
我遇到了类似的错误。导致此错误的原因是托管服务器应允许入站端口9200-9300。该错误指定尝试访问未授予权限的端口