From 979833a781de5fc95ee66e7fec5f891486235531 Mon Sep 17 00:00:00 2001 From: Georg von Kries Date: Fri, 6 Dec 2024 16:23:05 +0100 Subject: [PATCH] Fixes that elastic search is crashing the site when it's not configured. (#17138) --- .../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(); } }