elasticsearch9 9.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. elasticsearch9/__init__.py +98 -0
  2. elasticsearch9/_async/__init__.py +16 -0
  3. elasticsearch9/_async/client/__init__.py +6531 -0
  4. elasticsearch9/_async/client/_base.py +430 -0
  5. elasticsearch9/_async/client/async_search.py +637 -0
  6. elasticsearch9/_async/client/autoscaling.py +252 -0
  7. elasticsearch9/_async/client/cat.py +2995 -0
  8. elasticsearch9/_async/client/ccr.py +1043 -0
  9. elasticsearch9/_async/client/cluster.py +1223 -0
  10. elasticsearch9/_async/client/connector.py +1978 -0
  11. elasticsearch9/_async/client/dangling_indices.py +192 -0
  12. elasticsearch9/_async/client/enrich.py +291 -0
  13. elasticsearch9/_async/client/eql.py +359 -0
  14. elasticsearch9/_async/client/esql.py +490 -0
  15. elasticsearch9/_async/client/features.py +130 -0
  16. elasticsearch9/_async/client/fleet.py +658 -0
  17. elasticsearch9/_async/client/graph.py +113 -0
  18. elasticsearch9/_async/client/ilm.py +668 -0
  19. elasticsearch9/_async/client/indices.py +5582 -0
  20. elasticsearch9/_async/client/inference.py +2247 -0
  21. elasticsearch9/_async/client/ingest.py +766 -0
  22. elasticsearch9/_async/client/license.py +400 -0
  23. elasticsearch9/_async/client/logstash.py +176 -0
  24. elasticsearch9/_async/client/migration.py +160 -0
  25. elasticsearch9/_async/client/ml.py +5835 -0
  26. elasticsearch9/_async/client/monitoring.py +100 -0
  27. elasticsearch9/_async/client/nodes.py +543 -0
  28. elasticsearch9/_async/client/query_rules.py +485 -0
  29. elasticsearch9/_async/client/rollup.py +616 -0
  30. elasticsearch9/_async/client/search_application.py +574 -0
  31. elasticsearch9/_async/client/searchable_snapshots.py +313 -0
  32. elasticsearch9/_async/client/security.py +4688 -0
  33. elasticsearch9/_async/client/shutdown.py +268 -0
  34. elasticsearch9/_async/client/simulate.py +145 -0
  35. elasticsearch9/_async/client/slm.py +559 -0
  36. elasticsearch9/_async/client/snapshot.py +1338 -0
  37. elasticsearch9/_async/client/sql.py +469 -0
  38. elasticsearch9/_async/client/ssl.py +76 -0
  39. elasticsearch9/_async/client/synonyms.py +413 -0
  40. elasticsearch9/_async/client/tasks.py +295 -0
  41. elasticsearch9/_async/client/text_structure.py +664 -0
  42. elasticsearch9/_async/client/transform.py +922 -0
  43. elasticsearch9/_async/client/utils.py +48 -0
  44. elasticsearch9/_async/client/watcher.py +894 -0
  45. elasticsearch9/_async/client/xpack.py +134 -0
  46. elasticsearch9/_async/helpers.py +596 -0
  47. elasticsearch9/_otel.py +110 -0
  48. elasticsearch9/_sync/__init__.py +16 -0
  49. elasticsearch9/_sync/client/__init__.py +6529 -0
  50. elasticsearch9/_sync/client/_base.py +430 -0
  51. elasticsearch9/_sync/client/async_search.py +637 -0
  52. elasticsearch9/_sync/client/autoscaling.py +252 -0
  53. elasticsearch9/_sync/client/cat.py +2995 -0
  54. elasticsearch9/_sync/client/ccr.py +1043 -0
  55. elasticsearch9/_sync/client/cluster.py +1223 -0
  56. elasticsearch9/_sync/client/connector.py +1978 -0
  57. elasticsearch9/_sync/client/dangling_indices.py +192 -0
  58. elasticsearch9/_sync/client/enrich.py +291 -0
  59. elasticsearch9/_sync/client/eql.py +359 -0
  60. elasticsearch9/_sync/client/esql.py +490 -0
  61. elasticsearch9/_sync/client/features.py +130 -0
  62. elasticsearch9/_sync/client/fleet.py +658 -0
  63. elasticsearch9/_sync/client/graph.py +113 -0
  64. elasticsearch9/_sync/client/ilm.py +668 -0
  65. elasticsearch9/_sync/client/indices.py +5582 -0
  66. elasticsearch9/_sync/client/inference.py +2247 -0
  67. elasticsearch9/_sync/client/ingest.py +766 -0
  68. elasticsearch9/_sync/client/license.py +400 -0
  69. elasticsearch9/_sync/client/logstash.py +176 -0
  70. elasticsearch9/_sync/client/migration.py +160 -0
  71. elasticsearch9/_sync/client/ml.py +5835 -0
  72. elasticsearch9/_sync/client/monitoring.py +100 -0
  73. elasticsearch9/_sync/client/nodes.py +543 -0
  74. elasticsearch9/_sync/client/query_rules.py +485 -0
  75. elasticsearch9/_sync/client/rollup.py +616 -0
  76. elasticsearch9/_sync/client/search_application.py +574 -0
  77. elasticsearch9/_sync/client/searchable_snapshots.py +313 -0
  78. elasticsearch9/_sync/client/security.py +4688 -0
  79. elasticsearch9/_sync/client/shutdown.py +268 -0
  80. elasticsearch9/_sync/client/simulate.py +145 -0
  81. elasticsearch9/_sync/client/slm.py +559 -0
  82. elasticsearch9/_sync/client/snapshot.py +1338 -0
  83. elasticsearch9/_sync/client/sql.py +469 -0
  84. elasticsearch9/_sync/client/ssl.py +76 -0
  85. elasticsearch9/_sync/client/synonyms.py +413 -0
  86. elasticsearch9/_sync/client/tasks.py +295 -0
  87. elasticsearch9/_sync/client/text_structure.py +664 -0
  88. elasticsearch9/_sync/client/transform.py +922 -0
  89. elasticsearch9/_sync/client/utils.py +475 -0
  90. elasticsearch9/_sync/client/watcher.py +894 -0
  91. elasticsearch9/_sync/client/xpack.py +134 -0
  92. elasticsearch9/_utils.py +34 -0
  93. elasticsearch9/_version.py +18 -0
  94. elasticsearch9/client.py +126 -0
  95. elasticsearch9/compat.py +79 -0
  96. elasticsearch9/dsl/__init__.py +203 -0
  97. elasticsearch9/dsl/_async/__init__.py +16 -0
  98. elasticsearch9/dsl/_async/document.py +522 -0
  99. elasticsearch9/dsl/_async/faceted_search.py +50 -0
  100. elasticsearch9/dsl/_async/index.py +639 -0
  101. elasticsearch9/dsl/_async/mapping.py +49 -0
  102. elasticsearch9/dsl/_async/search.py +237 -0
  103. elasticsearch9/dsl/_async/update_by_query.py +47 -0
  104. elasticsearch9/dsl/_sync/__init__.py +16 -0
  105. elasticsearch9/dsl/_sync/document.py +514 -0
  106. elasticsearch9/dsl/_sync/faceted_search.py +50 -0
  107. elasticsearch9/dsl/_sync/index.py +597 -0
  108. elasticsearch9/dsl/_sync/mapping.py +49 -0
  109. elasticsearch9/dsl/_sync/search.py +230 -0
  110. elasticsearch9/dsl/_sync/update_by_query.py +45 -0
  111. elasticsearch9/dsl/aggs.py +3734 -0
  112. elasticsearch9/dsl/analysis.py +341 -0
  113. elasticsearch9/dsl/async_connections.py +37 -0
  114. elasticsearch9/dsl/connections.py +142 -0
  115. elasticsearch9/dsl/document.py +20 -0
  116. elasticsearch9/dsl/document_base.py +444 -0
  117. elasticsearch9/dsl/exceptions.py +32 -0
  118. elasticsearch9/dsl/faceted_search.py +28 -0
  119. elasticsearch9/dsl/faceted_search_base.py +489 -0
  120. elasticsearch9/dsl/field.py +4392 -0
  121. elasticsearch9/dsl/function.py +180 -0
  122. elasticsearch9/dsl/index.py +23 -0
  123. elasticsearch9/dsl/index_base.py +178 -0
  124. elasticsearch9/dsl/mapping.py +19 -0
  125. elasticsearch9/dsl/mapping_base.py +219 -0
  126. elasticsearch9/dsl/query.py +2822 -0
  127. elasticsearch9/dsl/response/__init__.py +388 -0
  128. elasticsearch9/dsl/response/aggs.py +100 -0
  129. elasticsearch9/dsl/response/hit.py +53 -0
  130. elasticsearch9/dsl/search.py +20 -0
  131. elasticsearch9/dsl/search_base.py +1053 -0
  132. elasticsearch9/dsl/serializer.py +34 -0
  133. elasticsearch9/dsl/types.py +6453 -0
  134. elasticsearch9/dsl/update_by_query.py +19 -0
  135. elasticsearch9/dsl/update_by_query_base.py +149 -0
  136. elasticsearch9/dsl/utils.py +687 -0
  137. elasticsearch9/dsl/wrappers.py +144 -0
  138. elasticsearch9/exceptions.py +133 -0
  139. elasticsearch9/helpers/__init__.py +41 -0
  140. elasticsearch9/helpers/actions.py +875 -0
  141. elasticsearch9/helpers/errors.py +40 -0
  142. elasticsearch9/helpers/vectorstore/__init__.py +62 -0
  143. elasticsearch9/helpers/vectorstore/_async/__init__.py +16 -0
  144. elasticsearch9/helpers/vectorstore/_async/_utils.py +39 -0
  145. elasticsearch9/helpers/vectorstore/_async/embedding_service.py +89 -0
  146. elasticsearch9/helpers/vectorstore/_async/strategies.py +487 -0
  147. elasticsearch9/helpers/vectorstore/_async/vectorstore.py +421 -0
  148. elasticsearch9/helpers/vectorstore/_sync/__init__.py +16 -0
  149. elasticsearch9/helpers/vectorstore/_sync/_utils.py +39 -0
  150. elasticsearch9/helpers/vectorstore/_sync/embedding_service.py +89 -0
  151. elasticsearch9/helpers/vectorstore/_sync/strategies.py +487 -0
  152. elasticsearch9/helpers/vectorstore/_sync/vectorstore.py +421 -0
  153. elasticsearch9/helpers/vectorstore/_utils.py +116 -0
  154. elasticsearch9/py.typed +0 -0
  155. elasticsearch9/serializer.py +250 -0
  156. elasticsearch9-9.0.0.dist-info/METADATA +175 -0
  157. elasticsearch9-9.0.0.dist-info/RECORD +160 -0
  158. elasticsearch9-9.0.0.dist-info/WHEEL +4 -0
  159. elasticsearch9-9.0.0.dist-info/licenses/LICENSE +176 -0
  160. elasticsearch9-9.0.0.dist-info/licenses/NOTICE +2 -0
@@ -0,0 +1,475 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ import base64
19
+ import inspect
20
+ import urllib.parse
21
+ import warnings
22
+ from datetime import date, datetime
23
+ from enum import Enum, auto
24
+ from functools import wraps
25
+ from typing import (
26
+ TYPE_CHECKING,
27
+ Any,
28
+ Awaitable,
29
+ Callable,
30
+ Collection,
31
+ Dict,
32
+ List,
33
+ Mapping,
34
+ Optional,
35
+ Sequence,
36
+ Set,
37
+ Tuple,
38
+ Type,
39
+ TypeVar,
40
+ Union,
41
+ )
42
+
43
+ from elastic_transport import (
44
+ AsyncTransport,
45
+ HttpHeaders,
46
+ NodeConfig,
47
+ RequestsHttpNode,
48
+ SniffOptions,
49
+ Transport,
50
+ )
51
+ from elastic_transport.client_utils import (
52
+ DEFAULT,
53
+ client_meta_version,
54
+ create_user_agent,
55
+ parse_cloud_id,
56
+ url_to_node_config,
57
+ )
58
+
59
+ from ..._version import __versionstr__
60
+ from ...compat import to_bytes, to_str, warn_stacklevel
61
+ from ...exceptions import GeneralAvailabilityWarning
62
+
63
+ if TYPE_CHECKING:
64
+ from ._base import NamespacedClient
65
+
66
+ # parts of URL to be omitted
67
+ SKIP_IN_PATH: Collection[Any] = (None, "", b"", [], ())
68
+
69
+ # To be passed to 'client_meta_service' on the Transport
70
+ CLIENT_META_SERVICE = ("es", client_meta_version(__versionstr__))
71
+
72
+ # Default User-Agent used by the client
73
+ USER_AGENT = create_user_agent("elasticsearch-py", __versionstr__)
74
+
75
+
76
+ class Stability(Enum):
77
+ STABLE = auto()
78
+ BETA = auto()
79
+ EXPERIMENTAL = auto()
80
+
81
+
82
+ _TYPE_HOSTS = Union[
83
+ str, Sequence[Union[str, Mapping[str, Union[str, int]], NodeConfig]]
84
+ ]
85
+
86
+ _TYPE_BODY = Union[bytes, str, Dict[str, Any]]
87
+
88
+ _TYPE_ASYNC_SNIFF_CALLBACK = Callable[
89
+ [AsyncTransport, SniffOptions], Awaitable[List[NodeConfig]]
90
+ ]
91
+ _TYPE_SYNC_SNIFF_CALLBACK = Callable[[Transport, SniffOptions], List[NodeConfig]]
92
+
93
+ _TRANSPORT_OPTIONS = {
94
+ "api_key",
95
+ "http_auth",
96
+ "request_timeout",
97
+ "opaque_id",
98
+ "headers",
99
+ "ignore",
100
+ }
101
+
102
+ F = TypeVar("F", bound=Callable[..., Any])
103
+
104
+
105
+ def client_node_configs(
106
+ hosts: Optional[_TYPE_HOSTS],
107
+ cloud_id: Optional[str],
108
+ requests_session_auth: Optional[Any] = None,
109
+ **kwargs: Any,
110
+ ) -> List[NodeConfig]:
111
+ if cloud_id is not None:
112
+ if hosts is not None:
113
+ raise ValueError(
114
+ "The 'cloud_id' and 'hosts' parameters are mutually exclusive"
115
+ )
116
+ node_configs = cloud_id_to_node_configs(cloud_id)
117
+ else:
118
+ assert hosts is not None
119
+ node_configs = hosts_to_node_configs(hosts)
120
+
121
+ # Remove all values which are 'DEFAULT' to avoid overwriting actual defaults.
122
+ node_options = {k: v for k, v in kwargs.items() if v is not DEFAULT}
123
+
124
+ # Set the 'User-Agent' default header.
125
+ headers = HttpHeaders(node_options.pop("headers", ()))
126
+ headers.setdefault("user-agent", USER_AGENT)
127
+ node_options["headers"] = headers
128
+
129
+ # If a custom Requests AuthBase is passed we set that via '_extras'.
130
+ if requests_session_auth is not None:
131
+ node_options.setdefault("_extras", {})[
132
+ "requests.session.auth"
133
+ ] = requests_session_auth
134
+
135
+ def apply_node_options(node_config: NodeConfig) -> NodeConfig:
136
+ """Needs special handling of headers since .replace() wipes out existing headers"""
137
+ headers = node_config.headers.copy() # type: ignore[attr-defined]
138
+
139
+ headers_to_add = node_options.pop("headers", ())
140
+ if headers_to_add:
141
+ headers.update(headers_to_add)
142
+
143
+ headers.setdefault("user-agent", USER_AGENT)
144
+ headers.freeze()
145
+ node_options["headers"] = headers
146
+ return node_config.replace(**node_options)
147
+
148
+ return [apply_node_options(node_config) for node_config in node_configs]
149
+
150
+
151
+ def hosts_to_node_configs(hosts: _TYPE_HOSTS) -> List[NodeConfig]:
152
+ """Transforms the many formats of 'hosts' into NodeConfigs"""
153
+
154
+ # To make the logic here simpler we reroute everything to be List[X]
155
+ if isinstance(hosts, str):
156
+ return hosts_to_node_configs([hosts])
157
+
158
+ node_configs: List[NodeConfig] = []
159
+ for host in hosts:
160
+ if isinstance(host, NodeConfig):
161
+ node_configs.append(host)
162
+
163
+ elif isinstance(host, str):
164
+ node_configs.append(url_to_node_config(host))
165
+
166
+ elif isinstance(host, Mapping):
167
+ node_configs.append(host_mapping_to_node_config(host))
168
+ else:
169
+ raise ValueError(
170
+ "'hosts' must be a list of URLs, NodeConfigs, or dictionaries"
171
+ )
172
+
173
+ return node_configs
174
+
175
+
176
+ def host_mapping_to_node_config(host: Mapping[str, Union[str, int]]) -> NodeConfig:
177
+ """Converts an old-style dictionary host specification to a NodeConfig"""
178
+
179
+ allow_hosts_keys = {
180
+ "scheme",
181
+ "host",
182
+ "port",
183
+ "path_prefix",
184
+ }
185
+ disallowed_keys = set(host.keys()).difference(allow_hosts_keys)
186
+ if disallowed_keys:
187
+ bad_keys_used = "', '".join(sorted(disallowed_keys))
188
+ allowed_keys = "', '".join(sorted(allow_hosts_keys))
189
+ raise ValueError(
190
+ f"Can't specify the options '{bad_keys_used}' via a "
191
+ f"dictionary in 'hosts', only '{allowed_keys}' options "
192
+ "are allowed"
193
+ )
194
+
195
+ options = dict(host)
196
+
197
+ return NodeConfig(**options) # type: ignore[arg-type]
198
+
199
+
200
+ def cloud_id_to_node_configs(cloud_id: str) -> List[NodeConfig]:
201
+ """Transforms an Elastic Cloud ID into a NodeConfig"""
202
+ es_addr = parse_cloud_id(cloud_id).es_address
203
+ if es_addr is None or not all(es_addr):
204
+ raise ValueError("Cloud ID missing host and port information for Elasticsearch")
205
+ host, port = es_addr
206
+ return [
207
+ NodeConfig(
208
+ scheme="https",
209
+ host=host,
210
+ port=port,
211
+ http_compress=True,
212
+ )
213
+ ]
214
+
215
+
216
+ def _base64_auth_header(auth_value: Union[str, List[str], Tuple[str, str]]) -> str:
217
+ """Takes either a 2-tuple or a base64-encoded string
218
+ and returns a base64-encoded string to be used
219
+ as an HTTP authorization header.
220
+ """
221
+ if isinstance(auth_value, (list, tuple)):
222
+ return base64.b64encode(to_bytes(":".join(auth_value))).decode("ascii")
223
+ return to_str(auth_value)
224
+
225
+
226
+ def _escape(value: Any) -> str:
227
+ """
228
+ Escape a single value of a URL string or a query parameter. If it is a list
229
+ or tuple, turn it into a comma-separated string first.
230
+ """
231
+
232
+ # make sequences into comma-separated stings
233
+ if isinstance(value, (list, tuple)):
234
+ value = ",".join([_escape(item) for item in value])
235
+
236
+ # dates and datetimes into isoformat
237
+ elif isinstance(value, (date, datetime)):
238
+ value = value.isoformat()
239
+
240
+ # make bools into true/false strings
241
+ elif isinstance(value, bool):
242
+ value = str(value).lower()
243
+
244
+ elif isinstance(value, bytes):
245
+ return value.decode("utf-8", "surrogatepass")
246
+
247
+ if not isinstance(value, str):
248
+ return str(value)
249
+ return value
250
+
251
+
252
+ def _quote(value: Any) -> str:
253
+ return urllib.parse.quote(_escape(value), ",*")
254
+
255
+
256
+ def _quote_query(query: Mapping[str, Any]) -> str:
257
+ return "&".join([f"{k}={_quote(v)}" for k, v in query.items()])
258
+
259
+
260
+ def _merge_kwargs_no_duplicates(kwargs: Dict[str, Any], values: Dict[str, Any]) -> None:
261
+ for key, val in values.items():
262
+ if key in kwargs:
263
+ raise ValueError(
264
+ f"Received multiple values for '{key}', specify parameters "
265
+ "directly instead of using 'params'"
266
+ )
267
+ kwargs[key] = val
268
+
269
+
270
+ def _merge_body_fields_no_duplicates(
271
+ body: _TYPE_BODY, kwargs: Dict[str, Any], body_fields: Tuple[str, ...]
272
+ ) -> bool:
273
+ mixed_body_and_params = False
274
+ for key in list(kwargs.keys()):
275
+ if key in body_fields:
276
+ if isinstance(body, (str, bytes)):
277
+ raise ValueError(
278
+ "Couldn't merge 'body' with other parameters as it wasn't a mapping."
279
+ )
280
+
281
+ if key in body:
282
+ raise ValueError(
283
+ f"Received multiple values for '{key}', specify parameters "
284
+ "using either body or parameters, not both."
285
+ )
286
+
287
+ warnings.warn(
288
+ f"Received '{key}' via a specific parameter in the presence of a "
289
+ "'body' parameter, which is deprecated and will be removed in a future "
290
+ "version. Instead, use only 'body' or only specific parameters.",
291
+ category=DeprecationWarning,
292
+ stacklevel=warn_stacklevel(),
293
+ )
294
+ body[key] = kwargs.pop(key)
295
+ mixed_body_and_params = True
296
+ return mixed_body_and_params
297
+
298
+
299
+ def _rewrite_parameters(
300
+ body_name: Optional[str] = None,
301
+ body_fields: Optional[Tuple[str, ...]] = None,
302
+ parameter_aliases: Optional[Dict[str, str]] = None,
303
+ ignore_deprecated_options: Optional[Set[str]] = None,
304
+ ) -> Callable[[F], F]:
305
+ def wrapper(api: F) -> F:
306
+ @wraps(api)
307
+ def wrapped(*args: Any, **kwargs: Any) -> Any:
308
+ # Let's give a nicer error message when users pass positional arguments.
309
+ if len(args) >= 2:
310
+ raise TypeError(
311
+ "Positional arguments can't be used with Elasticsearch API methods. "
312
+ "Instead only use keyword arguments."
313
+ )
314
+
315
+ # We merge 'params' first as transport options can be specified using params.
316
+ if "params" in kwargs and (
317
+ not ignore_deprecated_options
318
+ or "params" not in ignore_deprecated_options
319
+ ):
320
+ params = kwargs.pop("params")
321
+ if params:
322
+ if not hasattr(params, "items"):
323
+ raise ValueError(
324
+ "Couldn't merge 'params' with other parameters as it wasn't a mapping. "
325
+ "Instead of using 'params' use individual API parameters"
326
+ )
327
+ warnings.warn(
328
+ "The 'params' parameter is deprecated and will be removed "
329
+ "in a future version. Instead use individual parameters.",
330
+ category=DeprecationWarning,
331
+ stacklevel=warn_stacklevel(),
332
+ )
333
+ _merge_kwargs_no_duplicates(kwargs, params)
334
+
335
+ maybe_transport_options = _TRANSPORT_OPTIONS.intersection(kwargs)
336
+ if maybe_transport_options:
337
+ transport_options = {}
338
+ for option in maybe_transport_options:
339
+ if (
340
+ ignore_deprecated_options
341
+ and option in ignore_deprecated_options
342
+ ):
343
+ continue
344
+ try:
345
+ option_rename = option
346
+ if option == "ignore":
347
+ option_rename = "ignore_status"
348
+ transport_options[option_rename] = kwargs.pop(option)
349
+ except KeyError:
350
+ pass
351
+ if transport_options:
352
+ warnings.warn(
353
+ "Passing transport options in the API method is deprecated. Use 'Elasticsearch.options()' instead.",
354
+ category=DeprecationWarning,
355
+ stacklevel=warn_stacklevel(),
356
+ )
357
+ client = args[0]
358
+
359
+ # Namespaced clients need to unwrapped.
360
+ namespaced_client: Optional[Type["NamespacedClient"]] = None
361
+ if hasattr(client, "_client"):
362
+ namespaced_client = type(client)
363
+ client = client._client
364
+
365
+ client = client.options(**transport_options)
366
+
367
+ # Re-wrap the client if we unwrapped due to being namespaced.
368
+ if namespaced_client is not None:
369
+ client = namespaced_client(client)
370
+ args = (client,) + args[1:]
371
+
372
+ if "body" in kwargs and (
373
+ not ignore_deprecated_options or "body" not in ignore_deprecated_options
374
+ ):
375
+ body: Optional[_TYPE_BODY] = kwargs.pop("body")
376
+ mixed_body_and_params = False
377
+ if body is not None:
378
+ if body_name:
379
+ if body_name in kwargs:
380
+ raise TypeError(
381
+ f"Can't use '{body_name}' and 'body' parameters together because '{body_name}' "
382
+ "is an alias for 'body'. Instead you should only use the "
383
+ f"'{body_name}' parameter. See https://github.com/elastic/elasticsearch-py/"
384
+ "issues/1698 for more information"
385
+ )
386
+ kwargs[body_name] = body
387
+ elif body_fields is not None:
388
+ mixed_body_and_params = _merge_body_fields_no_duplicates(
389
+ body, kwargs, body_fields
390
+ )
391
+ kwargs["body"] = body
392
+
393
+ if parameter_aliases and not isinstance(body, (str, bytes)):
394
+ for alias, rename_to in parameter_aliases.items():
395
+ if rename_to in body:
396
+ body[alias] = body.pop(rename_to)
397
+ # If body and params are mixed, the alias may come from a param,
398
+ # in which case the warning below will not make sense.
399
+ if not mixed_body_and_params:
400
+ warnings.warn(
401
+ f"Using '{rename_to}' alias in 'body' is deprecated and will be removed "
402
+ f"in a future version of elasticsearch-py. Use '{alias}' directly instead. "
403
+ "See https://github.com/elastic/elasticsearch-py/issues/1698 for more information",
404
+ category=DeprecationWarning,
405
+ stacklevel=2,
406
+ )
407
+
408
+ if parameter_aliases:
409
+ for alias, rename_to in parameter_aliases.items():
410
+ try:
411
+ kwargs[rename_to] = kwargs.pop(alias)
412
+ except KeyError:
413
+ pass
414
+
415
+ return api(*args, **kwargs)
416
+
417
+ return wrapped # type: ignore[return-value]
418
+
419
+ return wrapper
420
+
421
+
422
+ def _stability_warning(
423
+ stability: Stability,
424
+ version: Optional[str] = None,
425
+ message: Optional[str] = None,
426
+ ) -> Callable[[F], F]:
427
+ def wrapper(api: F) -> F:
428
+ @wraps(api)
429
+ def wrapped(*args: Any, **kwargs: Any) -> Any:
430
+ if stability == Stability.BETA:
431
+ warnings.warn(
432
+ "This API is in beta and is subject to change. "
433
+ "The design and code is less mature than official GA features and is being provided as-is with no warranties. "
434
+ "Beta features are not subject to the support SLA of official GA features.",
435
+ category=GeneralAvailabilityWarning,
436
+ stacklevel=warn_stacklevel(),
437
+ )
438
+ elif stability == Stability.EXPERIMENTAL:
439
+ warnings.warn(
440
+ "This API is in technical preview and may be changed or removed in a future release. "
441
+ "Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.",
442
+ category=GeneralAvailabilityWarning,
443
+ stacklevel=warn_stacklevel(),
444
+ )
445
+
446
+ return api(*args, **kwargs)
447
+
448
+ return wrapped # type: ignore[return-value]
449
+
450
+ return wrapper
451
+
452
+
453
+ def is_requests_http_auth(http_auth: Any) -> bool:
454
+ """Detect if an http_auth value is a custom Requests auth object"""
455
+ try:
456
+ from requests.auth import AuthBase
457
+
458
+ return isinstance(http_auth, AuthBase)
459
+ except ImportError:
460
+ pass
461
+ return False
462
+
463
+
464
+ def is_requests_node_class(node_class: Any) -> bool:
465
+ """Detect if 'RequestsHttpNode' would be used given the setting of 'node_class'"""
466
+ return (
467
+ node_class is not None
468
+ and node_class is not DEFAULT
469
+ and (
470
+ node_class == "requests"
471
+ or (
472
+ inspect.isclass(node_class) and issubclass(node_class, RequestsHttpNode)
473
+ )
474
+ )
475
+ )