Elastic: fix ping

This commit is contained in:
pavelbannov 2022-01-21 13:56:23 +03:00
parent dd2c54ed86
commit 8863e41487

View File

@ -97,16 +97,12 @@ namespace ASC.ElasticSearch
}); });
} }
client = new ElasticClient(settings);
try try
{ {
var result = client.Ping(new PingRequest()); if (Ping(new ElasticClient(settings)))
var isValid = result.IsValid;
if (result.IsValid)
{ {
client = new ElasticClient(settings);
client.Ingest.PutPipeline("attachments", p => p client.Ingest.PutPipeline("attachments", p => p
.Processors(pp => pp .Processors(pp => pp
.Attachment<Attachment>(a => a.Field("document.data").TargetField("document.attachment")) .Attachment<Attachment>(a => a.Field("document.data").TargetField("document.attachment"))
@ -117,9 +113,10 @@ namespace ASC.ElasticSearch
catch (Exception e) catch (Exception e)
{ {
Log.Error(e); Log.Error(e);
client = null;
} }
return client; return client;
} }
} }
@ -127,11 +124,14 @@ namespace ASC.ElasticSearch
public bool Ping() public bool Ping()
{ {
var instance = Instance; return Ping(Instance);
}
if (instance == null) return false; private bool Ping(ElasticClient elasticClient)
{
if (elasticClient == null) return false;
var result = instance.Ping(new PingRequest()); var result = elasticClient.Ping(new PingRequest());
Log.DebugFormat("Ping {0}", result.DebugInformation); Log.DebugFormat("Ping {0}", result.DebugInformation);