elasticsearch 8.19.0__py3-none-any.whl → 8.19.2__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 (61) hide show
  1. elasticsearch/_async/client/__init__.py +39 -55
  2. elasticsearch/_async/client/cat.py +605 -35
  3. elasticsearch/_async/client/cluster.py +7 -2
  4. elasticsearch/_async/client/connector.py +3 -3
  5. elasticsearch/_async/client/esql.py +16 -6
  6. elasticsearch/_async/client/fleet.py +1 -5
  7. elasticsearch/_async/client/graph.py +1 -5
  8. elasticsearch/_async/client/ilm.py +2 -10
  9. elasticsearch/_async/client/indices.py +159 -32
  10. elasticsearch/_async/client/inference.py +142 -120
  11. elasticsearch/_async/client/nodes.py +2 -2
  12. elasticsearch/_async/client/shutdown.py +5 -15
  13. elasticsearch/_async/client/slm.py +1 -5
  14. elasticsearch/_async/client/snapshot.py +262 -112
  15. elasticsearch/_async/client/sql.py +1 -1
  16. elasticsearch/_async/client/streams.py +185 -0
  17. elasticsearch/_async/client/transform.py +60 -0
  18. elasticsearch/_async/client/watcher.py +1 -5
  19. elasticsearch/_async/helpers.py +58 -9
  20. elasticsearch/_sync/client/__init__.py +39 -55
  21. elasticsearch/_sync/client/cat.py +605 -35
  22. elasticsearch/_sync/client/cluster.py +7 -2
  23. elasticsearch/_sync/client/connector.py +3 -3
  24. elasticsearch/_sync/client/esql.py +16 -6
  25. elasticsearch/_sync/client/fleet.py +1 -5
  26. elasticsearch/_sync/client/graph.py +1 -5
  27. elasticsearch/_sync/client/ilm.py +2 -10
  28. elasticsearch/_sync/client/indices.py +159 -32
  29. elasticsearch/_sync/client/inference.py +142 -120
  30. elasticsearch/_sync/client/nodes.py +2 -2
  31. elasticsearch/_sync/client/shutdown.py +5 -15
  32. elasticsearch/_sync/client/slm.py +1 -5
  33. elasticsearch/_sync/client/snapshot.py +262 -112
  34. elasticsearch/_sync/client/sql.py +1 -1
  35. elasticsearch/_sync/client/streams.py +185 -0
  36. elasticsearch/_sync/client/transform.py +60 -0
  37. elasticsearch/_sync/client/watcher.py +1 -5
  38. elasticsearch/_version.py +2 -1
  39. elasticsearch/client.py +2 -0
  40. elasticsearch/compat.py +45 -1
  41. elasticsearch/dsl/__init__.py +28 -0
  42. elasticsearch/dsl/_async/document.py +84 -0
  43. elasticsearch/dsl/_sync/document.py +84 -0
  44. elasticsearch/dsl/aggs.py +117 -0
  45. elasticsearch/dsl/document_base.py +59 -1
  46. elasticsearch/dsl/field.py +60 -10
  47. elasticsearch/dsl/query.py +1 -1
  48. elasticsearch/dsl/response/__init__.py +3 -0
  49. elasticsearch/dsl/response/aggs.py +1 -1
  50. elasticsearch/dsl/types.py +325 -20
  51. elasticsearch/dsl/utils.py +1 -1
  52. elasticsearch/esql/__init__.py +2 -1
  53. elasticsearch/esql/esql.py +85 -34
  54. elasticsearch/esql/functions.py +37 -25
  55. elasticsearch/helpers/__init__.py +10 -1
  56. elasticsearch/helpers/actions.py +106 -33
  57. {elasticsearch-8.19.0.dist-info → elasticsearch-8.19.2.dist-info}/METADATA +2 -4
  58. {elasticsearch-8.19.0.dist-info → elasticsearch-8.19.2.dist-info}/RECORD +61 -59
  59. {elasticsearch-8.19.0.dist-info → elasticsearch-8.19.2.dist-info}/WHEEL +0 -0
  60. {elasticsearch-8.19.0.dist-info → elasticsearch-8.19.2.dist-info}/licenses/LICENSE +0 -0
  61. {elasticsearch-8.19.0.dist-info → elasticsearch-8.19.2.dist-info}/licenses/NOTICE +0 -0
@@ -0,0 +1,185 @@
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
+
19
+ import typing as t
20
+
21
+ from elastic_transport import ObjectApiResponse, TextApiResponse
22
+
23
+ from ._base import NamespacedClient
24
+ from .utils import (
25
+ Stability,
26
+ _rewrite_parameters,
27
+ _stability_warning,
28
+ )
29
+
30
+
31
+ class StreamsClient(NamespacedClient):
32
+
33
+ @_rewrite_parameters()
34
+ @_stability_warning(Stability.EXPERIMENTAL)
35
+ async def logs_disable(
36
+ self,
37
+ *,
38
+ error_trace: t.Optional[bool] = None,
39
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
40
+ human: t.Optional[bool] = None,
41
+ master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
42
+ pretty: t.Optional[bool] = None,
43
+ timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
44
+ ) -> t.Union[ObjectApiResponse[t.Any], TextApiResponse]:
45
+ """
46
+ .. raw:: html
47
+
48
+ <p>Disable logs stream.</p>
49
+ <p>Turn off the logs stream feature for this cluster.</p>
50
+
51
+
52
+ `<https://www.elastic.co/docs/api/doc/elasticsearch#TODO>`_
53
+
54
+ :param master_timeout: The period to wait for a connection to the master node.
55
+ If no response is received before the timeout expires, the request fails
56
+ and returns an error.
57
+ :param timeout: The period to wait for a response. If no response is received
58
+ before the timeout expires, the request fails and returns an error.
59
+ """
60
+ __path_parts: t.Dict[str, str] = {}
61
+ __path = "/_streams/logs/_disable"
62
+ __query: t.Dict[str, t.Any] = {}
63
+ if error_trace is not None:
64
+ __query["error_trace"] = error_trace
65
+ if filter_path is not None:
66
+ __query["filter_path"] = filter_path
67
+ if human is not None:
68
+ __query["human"] = human
69
+ if master_timeout is not None:
70
+ __query["master_timeout"] = master_timeout
71
+ if pretty is not None:
72
+ __query["pretty"] = pretty
73
+ if timeout is not None:
74
+ __query["timeout"] = timeout
75
+ __headers = {"accept": "application/json,text/plain"}
76
+ return await self.perform_request( # type: ignore[return-value]
77
+ "POST",
78
+ __path,
79
+ params=__query,
80
+ headers=__headers,
81
+ endpoint_id="streams.logs_disable",
82
+ path_parts=__path_parts,
83
+ )
84
+
85
+ @_rewrite_parameters()
86
+ @_stability_warning(Stability.EXPERIMENTAL)
87
+ async def logs_enable(
88
+ self,
89
+ *,
90
+ error_trace: t.Optional[bool] = None,
91
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
92
+ human: t.Optional[bool] = None,
93
+ master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
94
+ pretty: t.Optional[bool] = None,
95
+ timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
96
+ ) -> t.Union[ObjectApiResponse[t.Any], TextApiResponse]:
97
+ """
98
+ .. raw:: html
99
+
100
+ <p>Enable logs stream.</p>
101
+ <p>Turn on the logs stream feature for this cluster.</p>
102
+ <p>NOTE: To protect existing data, this feature can be turned on only if the
103
+ cluster does not have existing indices or data streams that match the pattern <code>logs|logs.*</code>.
104
+ If those indices or data streams exist, a <code>409 - Conflict</code> response and error is returned.</p>
105
+
106
+
107
+ `<https://www.elastic.co/docs/api/doc/elasticsearch#TODO>`_
108
+
109
+ :param master_timeout: The period to wait for a connection to the master node.
110
+ If no response is received before the timeout expires, the request fails
111
+ and returns an error.
112
+ :param timeout: The period to wait for a response. If no response is received
113
+ before the timeout expires, the request fails and returns an error.
114
+ """
115
+ __path_parts: t.Dict[str, str] = {}
116
+ __path = "/_streams/logs/_enable"
117
+ __query: t.Dict[str, t.Any] = {}
118
+ if error_trace is not None:
119
+ __query["error_trace"] = error_trace
120
+ if filter_path is not None:
121
+ __query["filter_path"] = filter_path
122
+ if human is not None:
123
+ __query["human"] = human
124
+ if master_timeout is not None:
125
+ __query["master_timeout"] = master_timeout
126
+ if pretty is not None:
127
+ __query["pretty"] = pretty
128
+ if timeout is not None:
129
+ __query["timeout"] = timeout
130
+ __headers = {"accept": "application/json,text/plain"}
131
+ return await self.perform_request( # type: ignore[return-value]
132
+ "POST",
133
+ __path,
134
+ params=__query,
135
+ headers=__headers,
136
+ endpoint_id="streams.logs_enable",
137
+ path_parts=__path_parts,
138
+ )
139
+
140
+ @_rewrite_parameters()
141
+ @_stability_warning(Stability.EXPERIMENTAL)
142
+ async def status(
143
+ self,
144
+ *,
145
+ error_trace: t.Optional[bool] = None,
146
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
147
+ human: t.Optional[bool] = None,
148
+ master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
149
+ pretty: t.Optional[bool] = None,
150
+ ) -> ObjectApiResponse[t.Any]:
151
+ """
152
+ .. raw:: html
153
+
154
+ <p>Get the status of streams.</p>
155
+ <p>Get the current status for all types of streams.</p>
156
+
157
+
158
+ `<https://www.elastic.co/docs/api/doc/elasticsearch#TODO>`_
159
+
160
+ :param master_timeout: Period to wait for a connection to the master node. If
161
+ no response is received before the timeout expires, the request fails and
162
+ returns an error.
163
+ """
164
+ __path_parts: t.Dict[str, str] = {}
165
+ __path = "/_streams/status"
166
+ __query: t.Dict[str, t.Any] = {}
167
+ if error_trace is not None:
168
+ __query["error_trace"] = error_trace
169
+ if filter_path is not None:
170
+ __query["filter_path"] = filter_path
171
+ if human is not None:
172
+ __query["human"] = human
173
+ if master_timeout is not None:
174
+ __query["master_timeout"] = master_timeout
175
+ if pretty is not None:
176
+ __query["pretty"] = pretty
177
+ __headers = {"accept": "application/json"}
178
+ return await self.perform_request( # type: ignore[return-value]
179
+ "GET",
180
+ __path,
181
+ params=__query,
182
+ headers=__headers,
183
+ endpoint_id="streams.status",
184
+ path_parts=__path_parts,
185
+ )
@@ -602,6 +602,66 @@ class TransformClient(NamespacedClient):
602
602
  path_parts=__path_parts,
603
603
  )
604
604
 
605
+ @_rewrite_parameters()
606
+ async def set_upgrade_mode(
607
+ self,
608
+ *,
609
+ enabled: t.Optional[bool] = None,
610
+ error_trace: t.Optional[bool] = None,
611
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
612
+ human: t.Optional[bool] = None,
613
+ pretty: t.Optional[bool] = None,
614
+ timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
615
+ ) -> ObjectApiResponse[t.Any]:
616
+ """
617
+ .. raw:: html
618
+
619
+ <p>Set upgrade_mode for transform indices.
620
+ Sets a cluster wide upgrade_mode setting that prepares transform
621
+ indices for an upgrade.
622
+ When upgrading your cluster, in some circumstances you must restart your
623
+ nodes and reindex your transform indices. In those circumstances,
624
+ there must be no transforms running. You can close the transforms,
625
+ do the upgrade, then open all the transforms again. Alternatively,
626
+ you can use this API to temporarily halt tasks associated with the transforms
627
+ and prevent new transforms from opening. You can also use this API
628
+ during upgrades that do not require you to reindex your transform
629
+ indices, though stopping transforms is not a requirement in that case.
630
+ You can see the current value for the upgrade_mode setting by using the get
631
+ transform info API.</p>
632
+
633
+
634
+ `<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-transform-set-upgrade-mode>`_
635
+
636
+ :param enabled: When `true`, it enables `upgrade_mode` which temporarily halts
637
+ all transform tasks and prohibits new transform tasks from starting.
638
+ :param timeout: The time to wait for the request to be completed.
639
+ """
640
+ __path_parts: t.Dict[str, str] = {}
641
+ __path = "/_transform/set_upgrade_mode"
642
+ __query: t.Dict[str, t.Any] = {}
643
+ if enabled is not None:
644
+ __query["enabled"] = enabled
645
+ if error_trace is not None:
646
+ __query["error_trace"] = error_trace
647
+ if filter_path is not None:
648
+ __query["filter_path"] = filter_path
649
+ if human is not None:
650
+ __query["human"] = human
651
+ if pretty is not None:
652
+ __query["pretty"] = pretty
653
+ if timeout is not None:
654
+ __query["timeout"] = timeout
655
+ __headers = {"accept": "application/json"}
656
+ return await self.perform_request( # type: ignore[return-value]
657
+ "POST",
658
+ __path,
659
+ params=__query,
660
+ headers=__headers,
661
+ endpoint_id="transform.set_upgrade_mode",
662
+ path_parts=__path_parts,
663
+ )
664
+
605
665
  @_rewrite_parameters(
606
666
  parameter_aliases={"from": "from_"},
607
667
  )
@@ -550,11 +550,7 @@ class WatcherClient(NamespacedClient):
550
550
  __body["transform"] = transform
551
551
  if trigger is not None:
552
552
  __body["trigger"] = trigger
553
- if not __body:
554
- __body = None # type: ignore[assignment]
555
- __headers = {"accept": "application/json"}
556
- if __body is not None:
557
- __headers["content-type"] = "application/json"
553
+ __headers = {"accept": "application/json", "content-type": "application/json"}
558
554
  return await self.perform_request( # type: ignore[return-value]
559
555
  "PUT",
560
556
  __path,
@@ -33,12 +33,16 @@ from typing import (
33
33
  Union,
34
34
  )
35
35
 
36
+ from ..compat import safe_task
36
37
  from ..exceptions import ApiError, NotFoundError, TransportError
37
38
  from ..helpers.actions import (
38
39
  _TYPE_BULK_ACTION,
39
40
  _TYPE_BULK_ACTION_BODY,
40
41
  _TYPE_BULK_ACTION_HEADER,
41
42
  _TYPE_BULK_ACTION_HEADER_AND_BODY,
43
+ _TYPE_BULK_ACTION_HEADER_WITH_META_AND_BODY,
44
+ _TYPE_BULK_ACTION_WITH_META,
45
+ BulkMeta,
42
46
  _ActionChunker,
43
47
  _process_bulk_chunk_error,
44
48
  _process_bulk_chunk_success,
@@ -54,9 +58,10 @@ T = TypeVar("T")
54
58
 
55
59
 
56
60
  async def _chunk_actions(
57
- actions: AsyncIterable[_TYPE_BULK_ACTION_HEADER_AND_BODY],
61
+ actions: AsyncIterable[_TYPE_BULK_ACTION_HEADER_WITH_META_AND_BODY],
58
62
  chunk_size: int,
59
63
  max_chunk_bytes: int,
64
+ flush_after_seconds: Optional[float],
60
65
  serializer: Serializer,
61
66
  ) -> AsyncIterable[
62
67
  Tuple[
@@ -76,10 +81,42 @@ async def _chunk_actions(
76
81
  chunker = _ActionChunker(
77
82
  chunk_size=chunk_size, max_chunk_bytes=max_chunk_bytes, serializer=serializer
78
83
  )
79
- async for action, data in actions:
80
- ret = chunker.feed(action, data)
81
- if ret:
82
- yield ret
84
+
85
+ if not flush_after_seconds:
86
+ async for action, data in actions:
87
+ ret = chunker.feed(action, data)
88
+ if ret:
89
+ yield ret
90
+ else:
91
+ item_queue: asyncio.Queue[_TYPE_BULK_ACTION_HEADER_WITH_META_AND_BODY] = (
92
+ asyncio.Queue()
93
+ )
94
+
95
+ async def get_items() -> None:
96
+ try:
97
+ async for item in actions:
98
+ await item_queue.put(item)
99
+ finally:
100
+ await item_queue.put((BulkMeta.done, None))
101
+
102
+ async with safe_task(get_items()):
103
+ timeout: Optional[float] = flush_after_seconds
104
+ while True:
105
+ try:
106
+ action, data = await asyncio.wait_for(
107
+ item_queue.get(), timeout=timeout
108
+ )
109
+ timeout = flush_after_seconds
110
+ except asyncio.TimeoutError:
111
+ action, data = BulkMeta.flush, None
112
+ timeout = None
113
+
114
+ if action is BulkMeta.done:
115
+ break
116
+ ret = chunker.feed(action, data)
117
+ if ret:
118
+ yield ret
119
+
83
120
  ret = chunker.flush()
84
121
  if ret:
85
122
  yield ret
@@ -159,9 +196,13 @@ async def azip(
159
196
 
160
197
  async def async_streaming_bulk(
161
198
  client: AsyncElasticsearch,
162
- actions: Union[Iterable[_TYPE_BULK_ACTION], AsyncIterable[_TYPE_BULK_ACTION]],
199
+ actions: Union[
200
+ Iterable[_TYPE_BULK_ACTION_WITH_META],
201
+ AsyncIterable[_TYPE_BULK_ACTION_WITH_META],
202
+ ],
163
203
  chunk_size: int = 500,
164
204
  max_chunk_bytes: int = 100 * 1024 * 1024,
205
+ flush_after_seconds: Optional[float] = None,
165
206
  raise_on_error: bool = True,
166
207
  expand_action_callback: Callable[
167
208
  [_TYPE_BULK_ACTION], _TYPE_BULK_ACTION_HEADER_AND_BODY
@@ -194,6 +235,9 @@ async def async_streaming_bulk(
194
235
  :arg actions: iterable or async iterable containing the actions to be executed
195
236
  :arg chunk_size: number of docs in one chunk sent to es (default: 500)
196
237
  :arg max_chunk_bytes: the maximum size of the request in bytes (default: 100MB)
238
+ :arg flush_after_seconds: time in seconds after which a chunk is written even
239
+ if hasn't reached `chunk_size` or `max_chunk_bytes`. Set to 0 to not use a
240
+ timeout-based flush. (default: 0)
197
241
  :arg raise_on_error: raise ``BulkIndexError`` containing errors (as `.errors`)
198
242
  from the execution of the last chunk when some occur. By default we raise.
199
243
  :arg raise_on_exception: if ``False`` then don't propagate exceptions from
@@ -220,9 +264,14 @@ async def async_streaming_bulk(
220
264
  if isinstance(retry_on_status, int):
221
265
  retry_on_status = (retry_on_status,)
222
266
 
223
- async def map_actions() -> AsyncIterable[_TYPE_BULK_ACTION_HEADER_AND_BODY]:
267
+ async def map_actions() -> (
268
+ AsyncIterable[_TYPE_BULK_ACTION_HEADER_WITH_META_AND_BODY]
269
+ ):
224
270
  async for item in aiter(actions):
225
- yield expand_action_callback(item)
271
+ if isinstance(item, BulkMeta):
272
+ yield item, None
273
+ else:
274
+ yield expand_action_callback(item)
226
275
 
227
276
  serializer = client.transport.serializers.get_serializer("application/json")
228
277
 
@@ -234,7 +283,7 @@ async def async_streaming_bulk(
234
283
  ]
235
284
  bulk_actions: List[bytes]
236
285
  async for bulk_data, bulk_actions in _chunk_actions(
237
- map_actions(), chunk_size, max_chunk_bytes, serializer
286
+ map_actions(), chunk_size, max_chunk_bytes, flush_after_seconds, serializer
238
287
  ):
239
288
  for attempt in range(max_retries + 1):
240
289
  to_retry: List[bytes] = []