ProgLearner ProgLearner - 1 month ago 15
C# Question

Nest 2.4.6 error when SniffingConnectionPool is being used

Without SniffingConnectionPool seem to work.

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


But using SniffingConnectionPool in ConnectionSettings below:

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


Results in error below:
"Failed sniffing cluster state."

Splunk log

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


Full trace:

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

Answer

Apparently there is a bug in ES 5.0. Replacing SniffingConnectionPool to SingleNodeConnectionPool should do the job.

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);