From eb3a300b3e1f9bbc1bb3b35bb94abcd6b4cd900b Mon Sep 17 00:00:00 2001 From: Georg von Kries Date: Fri, 6 Dec 2024 15:55:17 +0100 Subject: [PATCH] Fixes that elastic search is crashing the site when it's not configured. --- .../Services/ElasticSearchClientFactory.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticSearchClientFactory.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticSearchClientFactory.cs index b67e4fcd115..7fa1b401572 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticSearchClientFactory.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticSearchClientFactory.cs @@ -14,7 +14,7 @@ public static ElasticsearchClient Create(ElasticsearchConnectionOptions elasticC ElasticsearchConnectionType.StaticConnectionPool => new ElasticsearchClientSettings(new StaticNodePool(GetNodeUris(elasticConfiguration))), ElasticsearchConnectionType.SniffingConnectionPool => new ElasticsearchClientSettings(new SniffingNodePool(GetNodeUris(elasticConfiguration))), ElasticsearchConnectionType.StickyConnectionPool => new ElasticsearchClientSettings(new StickyNodePool(GetNodeUris(elasticConfiguration))), - _ => new ElasticsearchClientSettings(GetNodeUris(elasticConfiguration).First()), + _ => new ElasticsearchClientSettings(GetNodeUris(elasticConfiguration).FirstOrDefault()), }; if (!string.IsNullOrWhiteSpace(elasticConfiguration.CertificateFingerprint)) @@ -29,6 +29,11 @@ public static ElasticsearchClient Create(ElasticsearchConnectionOptions elasticC private static IEnumerable GetNodeUris(ElasticsearchConnectionOptions elasticConfiguration) { + if (string.IsNullOrEmpty(elasticConfiguration.Url)) + { + return []; + } + return elasticConfiguration.Ports.Select(port => new Uri($"{elasticConfiguration.Url}:{port}")).Distinct(); } }