File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
test_elasticsearch_serverless/test_client Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,7 @@ class AsyncElasticsearch(BaseClient):
121
121
def __init__ (
122
122
self ,
123
123
host : t .Optional [_TYPE_HOST ] = None ,
124
+ hosts : t .Optional [t .List [_TYPE_HOST ]] = None ,
124
125
* ,
125
126
# API
126
127
cloud_id : t .Optional [str ] = None ,
@@ -166,6 +167,14 @@ def __init__(
166
167
# Internal use only
167
168
_transport : t .Optional [AsyncTransport ] = None ,
168
169
) -> None :
170
+ if host is not None and hosts is not None :
171
+ raise ValueError ("Can't specify both 'host' and 'hosts'" )
172
+
173
+ if hosts is not None :
174
+ if len (hosts ) > 1 :
175
+ raise ValueError ("Can't specify more than one host in 'hosts'" )
176
+ host = hosts [0 ]
177
+
169
178
if host is None and cloud_id is None and _transport is None :
170
179
raise ValueError ("Either 'host' or 'cloud_id' must be specified" )
171
180
Original file line number Diff line number Diff line change @@ -121,6 +121,7 @@ class Elasticsearch(BaseClient):
121
121
def __init__ (
122
122
self ,
123
123
host : t .Optional [_TYPE_HOST ] = None ,
124
+ hosts : t .Optional [t .List [_TYPE_HOST ]] = None ,
124
125
* ,
125
126
# API
126
127
cloud_id : t .Optional [str ] = None ,
@@ -166,6 +167,14 @@ def __init__(
166
167
# Internal use only
167
168
_transport : t .Optional [Transport ] = None ,
168
169
) -> None :
170
+ if host is not None and hosts is not None :
171
+ raise ValueError ("Can't specify both 'host' and 'hosts'" )
172
+
173
+ if hosts is not None :
174
+ if len (hosts ) > 1 :
175
+ raise ValueError ("Can't specify more than one host in 'hosts'" )
176
+ host = hosts [0 ]
177
+
169
178
if host is None and cloud_id is None and _transport is None :
170
179
raise ValueError ("Either 'host' or 'cloud_id' must be specified" )
171
180
Original file line number Diff line number Diff line change @@ -469,3 +469,19 @@ def test_options_timeout_parameters(self):
469
469
"retry_on_status" : (404 ,),
470
470
"retry_on_timeout" : True ,
471
471
}
472
+
473
+ def test_host_vs_hosts (self ):
474
+ with pytest .raises (ValueError ) as e :
475
+ Elasticsearch (
476
+ host = "http://localhost:9200" ,
477
+ hosts = ["http://localhost:9200" , "http://localhost:9201" ],
478
+ transport_class = DummyTransport ,
479
+ )
480
+ assert str (e .value ) == "Can't specify both 'host' and 'hosts'"
481
+
482
+ with pytest .raises (ValueError ) as e :
483
+ Elasticsearch (
484
+ hosts = ["http://localhost:9200" , "http://localhost:9201" ],
485
+ transport_class = DummyTransport ,
486
+ )
487
+ assert str (e .value ) == "Can't specify more than one host in 'hosts'"
You can’t perform that action at this time.
0 commit comments