Skip to content

Commit 6a46ec9

Browse files
committed
Fallback to handle elasticsearch connection string
1 parent 90f8ae3 commit 6a46ec9

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/Exceptionless.Core/Configuration/ElasticsearchOptions.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,33 @@ public static ElasticsearchOptions ReadFromConfiguration(IConfiguration config,
5151

5252
private static void ParseConnectionString(string? connectionString, ElasticsearchOptions options, AppMode appMode)
5353
{
54-
var pairs = connectionString.ParseConnectionString();
55-
options.ServerUrl = pairs.GetString("server", "http://localhost:9200");
54+
try
55+
{
56+
var pairs = connectionString.ParseConnectionString();
57+
options.ServerUrl = pairs.GetString("server", "http://localhost:9200");
5658

57-
int shards = pairs.GetValueOrDefault<int>("shards", 1);
58-
options.NumberOfShards = shards > 0 ? shards : 1;
59+
int shards = pairs.GetValueOrDefault<int>("shards", 1);
60+
options.NumberOfShards = shards > 0 ? shards : 1;
5961

60-
int replicas = pairs.GetValueOrDefault<int>("replicas", appMode == AppMode.Production ? 1 : 0);
61-
options.NumberOfReplicas = replicas > 0 ? replicas : 0;
62+
int replicas = pairs.GetValueOrDefault<int>("replicas", appMode == AppMode.Production ? 1 : 0);
63+
options.NumberOfReplicas = replicas > 0 ? replicas : 0;
6264

63-
int fieldsLimit = pairs.GetValueOrDefault("field-limit", 1500);
64-
options.FieldsLimit = fieldsLimit > 0 ? fieldsLimit : 1500;
65+
int fieldsLimit = pairs.GetValueOrDefault("field-limit", 1500);
66+
options.FieldsLimit = fieldsLimit > 0 ? fieldsLimit : 1500;
6567

66-
options.EnableMapperSizePlugin = pairs.GetValueOrDefault("enable-size-plugin", appMode != AppMode.Development);
68+
options.EnableMapperSizePlugin = pairs.GetValueOrDefault("enable-size-plugin", appMode != AppMode.Development);
6769

68-
options.UserName = pairs.GetString("username");
69-
options.Password = pairs.GetString("password");
70+
options.UserName = pairs.GetString("username");
71+
options.Password = pairs.GetString("password");
7072

71-
string scope = pairs.GetString(nameof(options.Scope).ToLowerInvariant());
72-
if (!String.IsNullOrEmpty(scope))
73-
options.Scope = scope;
73+
string scope = pairs.GetString(nameof(options.Scope).ToLowerInvariant());
74+
if (!String.IsNullOrEmpty(scope))
75+
options.Scope = scope;
76+
}
77+
catch
78+
{
79+
options.ServerUrl = connectionString ?? String.Empty;
80+
return;
81+
}
7482
}
7583
}

0 commit comments

Comments
 (0)