使用 SniffingConnectionPool 时出现 Nest 2.4.6 错误

Nest 2.4.6 error when SniffingConnectionPool is being used

没有 SniffingConnectionPool 似乎可以工作。

var settings2 = new ConnectionSettings(new Uri(elasticSearchUri))
_elasticClient = new ElasticClient(settings2);

但在下面的 ConnectionSettings 中使用 SniffingConnectionPool

var settings2 = new ConnectionSettings(new SniffingConnectionPool(new[] { new Uri(elasticSearchUri) }))
                .DefaultIndex("myindex")
                .DisableDirectStreaming(true);

导致以下错误: "Failed sniffing cluster state."

Splunk 日志

Unable to import data to ElasticSearch - Failed sniffing cluster state.             PipelineException   Project.ScheduledJobService LOCAL   ERROR
Unable to import data to ElasticSearch - One or more errors occurred.               AggregateException  Project.ScheduledJobService LOCAL   ERROR
Unable to import data to ElasticSearch - Object reference not set to an instance of an object.
NullReferenceException  Project.ScheduledJobService

完整跟踪:

 at Elasticsearch.Net.RequestPipeline.Sniff() in C:\Users\russ\source\elasticsearch-net-2.x\src\Elasticsearch.Net\Transport\Pipeline\RequestPipeline.cs:line 358
  at Elasticsearch.Net.RequestPipeline.FirstPoolUsage(SemaphoreSlim semaphore) in C:\Users\russ\source\elasticsearch-net-2.x\src\Elasticsearch.Net\Transport\Pipeline\RequestPipeline.cs:line 143
  at Elasticsearch.Net.Transport`1.Request[TReturn](HttpMethod method, String path, PostData`1 data, IRequestParameters requestParameters) in C:\Users\russ\source\elasticsearch-net-2.x\src\Elasticsearch.Net\Transport\Transport.cs:line 53
  at Elasticsearch.Net.ElasticLowLevelClient.DoRequest[T](HttpMethod method, String path, PostData`1 data, IRequestParameters requestParameters) in C:\Users\russ\source\elasticsearch-net-2.x\src\Elasticsearch.Net\ElasticLowLevelClient.cs:line 58
  at Elasticsearch.Net.ElasticLowLevelClient.Bulk[T](PostData`1 body, Func`2 requestParameters) in C:\Users\russ\source\elasticsearch-net-2.x\src\Elasticsearch.Net\ElasticLowLevelClient.Generated.cs:line 32
  at Nest.LowLevelDispatch.BulkDispatch[T](IRequest`1 p, PostData`1 body) in C:\Users\russ\source\elasticsearch-net-2.x\src\Nest\_Generated\_LowLevelDispatch.generated.cs:line 26
  at Nest.ElasticClient.Nest.IHighLevelToLowLevelDispatcher.Dispatch[TRequest,TQueryString,TResponse](TRequest request, Func`3 responseGenerator, Func`3 dispatch) in C:\Users\russ\source\elasticsearch-net-2.x\src\Nest\ElasticClient.cs:line 56
  at Nest.ElasticClient.Nest.IHighLevelToLowLevelDispatcher.Dispatch[TRequest,TQueryString,TResponse](TRequest request, Func`3 dispatch) in C:\Users\russ\source\elasticsearch-net-2.x\src\Nest\ElasticClient.cs:line 46
  at Nest.ElasticClient.Bulk(IBulkRequest request) in C:\Users\russ\source\elasticsearch-net-2.x\src\Nest\Document\Multiple\Bulk\ElasticClient-Bulk.cs:line 32
  at Project.Core.Services.ElasticSearchService.IndexMultiple(IEnumerable`1 documents)
  at Project.ScheduledJobService.Jobs.ElasticSearch.ElasticSearchTrackedChangesDataImportJob.Execute() in C:\Users\Martynas.Valaika\Code\Project\Main\Source\Project\Project.ScheduledJobService\Jobs\Elasticsearch\ElasticSearchTrackedChangesDataImportJob.cs:line 35

显然 ES 5.0 中存在错误。将 SniffingConnectionPool 替换为 SingleNodeConnectionPool 应该可以完成这项工作。

var pool = new SingleNodeConnectionPool(new Uri(uri));
                var settings = new ConnectionSettings(pool, connectionSettings => new MyJsonNetSerializer(connectionSettings))
                    .DefaultIndex("seetickets_search_results")
                    .DisableDirectStreaming();

                _elasticClient = new ElasticClient(settings);