Skip to content

Commit

Permalink
Fixes that elastic search is crashing the site when it's not configur…
Browse files Browse the repository at this point in the history
…ed. (#17138)
  • Loading branch information
gvkries authored Dec 6, 2024
1 parent e7dbd6d commit 979833a
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -29,6 +29,11 @@ public static ElasticsearchClient Create(ElasticsearchConnectionOptions elasticC

private static IEnumerable<Uri> GetNodeUris(ElasticsearchConnectionOptions elasticConfiguration)
{
if (string.IsNullOrEmpty(elasticConfiguration.Url))
{
return [];
}

return elasticConfiguration.Ports.Select(port => new Uri($"{elasticConfiguration.Url}:{port}")).Distinct();
}
}

0 comments on commit 979833a

Please sign in to comment.