首页 > 解决方案 > 从 Azure 函数执行时,Nest 无法写入 ES

问题描述

我确实有 azure 函数,它监听事件并将数据写入 ES,但随机失败。

Exception while executing function: ElasticSearchIndexer Invalid NEST response built from a unsuccessful low level call on POST: /_bulk
 # Invalid Bulk items:
 # Audit trail of this API call:
 - [1] AllNodesDead: Took: 00:00:00
 - [2] Resurrection: Node: http://ip:9200/ Took: 00:00:00
 - [3] PingFailure: Node: http://ip:9200/ Exception: PipelineException Took: 00:00:02.0095670
 # OriginalException: Elasticsearch.Net.ElasticsearchClientException: Failed to ping the specified node.. Call: Status code unknown from: HEAD / ---> Elasticsearch.Net.PipelineException: Failed to ping the specified node. ---> Elasticsearch.Net.PipelineException: An error occurred trying to read the response from the specified node. ---> System.Net.WebException: The request was aborted: The request was canceled.
 at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
 at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
 --- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Elasticsearch.Net.HttpWebRequestConnection.<RequestAsync>d__5`1.MoveNext()
 --- End of inner exception stack trace ---
 at Elasticsearch.Net.RequestPipeline.<PingAsync>d__65.MoveNext()
 --- End of inner exception stack trace ---
 at Elasticsearch.Net.RequestPipeline.<PingAsync>d__65.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Elasticsearch.Net.Transport`1.<PingAsync>d__21.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 at Elasticsearch.Net.Transport`1.<PingAsync>d__21.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Elasticsearch.Net.Transport`1.<RequestAsync>d__15`1.MoveNext()
 --- 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 request was aborted: The request was canceled.
 at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
 at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
 --- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Elasticsearch.Net.HttpWebRequestConnection.<RequestAsync>d__5`1.MoveNext()
 --- End of inner exception stack trace ---
 at Elasticsearch.Net.RequestPipeline.<PingAsync>d__65.MoveNext()
 # 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.>

我在 DI 注册。

            var uris = FlymarkAppSettings.Instance.ElasticServerConnection.Split(';').Select(url => new Uri(url));
            var settings = new ConnectionSettings(new StaticConnectionPool(uris));
#if DEBUG
            settings.EnableDebugMode();
#endif

            builder.Register(c => new ElasticClient(settings))
                .As<IElasticClient>()
                .SingleInstance();

标签: elasticsearchazure-functionsnestelasticsearch-net

解决方案


推荐阅读