@@ -51,25 +51,33 @@ public static ElasticsearchOptions ReadFromConfiguration(IConfiguration config,
51
51
52
52
private static void ParseConnectionString ( string ? connectionString , ElasticsearchOptions options , AppMode appMode )
53
53
{
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" ) ;
56
58
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 ;
59
61
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 ;
62
64
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 ;
65
67
66
- options . EnableMapperSizePlugin = pairs . GetValueOrDefault ( "enable-size-plugin" , appMode != AppMode . Development ) ;
68
+ options . EnableMapperSizePlugin = pairs . GetValueOrDefault ( "enable-size-plugin" , appMode != AppMode . Development ) ;
67
69
68
- options . UserName = pairs . GetString ( "username" ) ;
69
- options . Password = pairs . GetString ( "password" ) ;
70
+ options . UserName = pairs . GetString ( "username" ) ;
71
+ options . Password = pairs . GetString ( "password" ) ;
70
72
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
+ }
74
82
}
75
83
}
0 commit comments