sniffing 使用说明

https://elasticstack.blog.csdn.net/article/details/107199603

1、如果你的 Elasticsearch 集群安装于自己的单独网络中(比如 docker 的安装情形),会发生什么?
2、如果你的 Elasticsearch 集群位于负载均衡器后面怎么办?

curl -s localhost:9200/nodes/all/http | jq .nodes[].http.publish_address

curl {ip_address}:9200 | jq .

如何避免上面的错误?

要解决此问题,你可以配置 Elasticsearch 绑定到其主机,但对外通告的是另外一个。 http.publish_host 配置选项正是这样做的。 现在,尝试使用此新配置运行上述 Docker 命令:

docker run -p 9200:9200 -e “discovery.type=single-node” -e “http.publish_host=localhost” docker.elastic.co/elasticsearch/elasticsearch:7.8.0
现在你再次重新运行:

$ curl -s localhost:9200/nodes/all/http | jq .nodes[].http.publish_address
“localhost/127.0.0.1:9200”
在上面,我们可以看到:

“localhost/{ip_address}:9200”

Failed sniffing cluster state

at Elasticsearch.Net.RequestPipeline.Sniff()\\r\\n   at Elasticsearch.Net.RequestPipeline.FirstPoolUsage(SemaphoreSlim semaphore)\\r\\n   at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)\\r\\n   at Elasticsearch.Net.ElasticLowLevelClient.DoRequest[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)\\r\\n   at Nest.ElasticClient.DoRequest[TRequest,TResponse](TRequest p, IRequestParameters parameters, Action`2 forceConfiguration)\\r\\n   at Nest.NamespacedClientProxy.DoRequest[TRequest,TResponse](TRequest p, IRequestParameters parameters, Action`2 forceConfiguration)\\r\\n   at Nest.Specification.IndicesApi.IndicesNamespace.Exists(IIndexExistsRequest request)\\r\\n   at Nest.Specification.IndicesApi.IndicesNamespace.Exists(Indices index, Func`2 selector)\\r\\n   at RG3.DO.Elasticsearch.Providers.BaseEsContext`1.InsertMany(List`1 tList) in C:\\\\0_RG\\\\Code\\\\rg3-pf\\\\RG3.DO.Elasticsearch\\\\Providers\\\\BaseEsContext.cs:line 41\\r\\n   at RG3.PF.Web.StartUsed.Controller.DebugEsController.AddEsAddress(List`1 addressList) in C:\\\\0_RG\\\\Code\\\\rg3-pf\\\\RG3.PF.Web.StartUsed\\\\Controllers\\\\DebugEsController.cs:line 50\\r\\n   at lambda_method(Closure , Object , Object[] )\\r\\n   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)\\r\\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\\r\\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()\\r\\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\\r\\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)\\r\\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\\r\\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\\r\\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)\\r\\n   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)\\r\\n   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)\\r\\n   at RG3.PF.Abstractions.Middlewares.GlobalExceptionMiddleware.Invoke(HttpContext context) in C:\\\\0_RG\\\\Code\\\\rg3-pf\\\\RG3.PF.Abstractions\\\\Middlewares\\\\GlobalExceptionMiddleware.cs:line 52

显然,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);

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);
文档更新时间: 2021-09-07 08:00   作者:admin