elasticsearch 9.1.1__py3-none-any.whl → 9.2.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 (76) hide show
  1. elasticsearch/_async/client/__init__.py +96 -44
  2. elasticsearch/_async/client/async_search.py +7 -0
  3. elasticsearch/_async/client/cat.py +489 -26
  4. elasticsearch/_async/client/cluster.py +9 -8
  5. elasticsearch/_async/client/connector.py +3 -3
  6. elasticsearch/_async/client/eql.py +7 -0
  7. elasticsearch/_async/client/esql.py +26 -3
  8. elasticsearch/_async/client/fleet.py +1 -5
  9. elasticsearch/_async/client/graph.py +1 -5
  10. elasticsearch/_async/client/ilm.py +2 -10
  11. elasticsearch/_async/client/indices.py +181 -37
  12. elasticsearch/_async/client/inference.py +291 -124
  13. elasticsearch/_async/client/ingest.py +8 -0
  14. elasticsearch/_async/client/license.py +4 -2
  15. elasticsearch/_async/client/logstash.py +3 -1
  16. elasticsearch/_async/client/ml.py +2 -2
  17. elasticsearch/_async/client/nodes.py +3 -5
  18. elasticsearch/_async/client/project.py +67 -0
  19. elasticsearch/_async/client/security.py +39 -0
  20. elasticsearch/_async/client/shutdown.py +5 -15
  21. elasticsearch/_async/client/simulate.py +8 -0
  22. elasticsearch/_async/client/slm.py +1 -5
  23. elasticsearch/_async/client/snapshot.py +20 -10
  24. elasticsearch/_async/client/sql.py +7 -0
  25. elasticsearch/_async/client/streams.py +185 -0
  26. elasticsearch/_async/client/watcher.py +1 -5
  27. elasticsearch/_async/helpers.py +74 -12
  28. elasticsearch/_sync/client/__init__.py +96 -44
  29. elasticsearch/_sync/client/async_search.py +7 -0
  30. elasticsearch/_sync/client/cat.py +489 -26
  31. elasticsearch/_sync/client/cluster.py +9 -8
  32. elasticsearch/_sync/client/connector.py +3 -3
  33. elasticsearch/_sync/client/eql.py +7 -0
  34. elasticsearch/_sync/client/esql.py +26 -3
  35. elasticsearch/_sync/client/fleet.py +1 -5
  36. elasticsearch/_sync/client/graph.py +1 -5
  37. elasticsearch/_sync/client/ilm.py +2 -10
  38. elasticsearch/_sync/client/indices.py +181 -37
  39. elasticsearch/_sync/client/inference.py +291 -124
  40. elasticsearch/_sync/client/ingest.py +8 -0
  41. elasticsearch/_sync/client/license.py +4 -2
  42. elasticsearch/_sync/client/logstash.py +3 -1
  43. elasticsearch/_sync/client/ml.py +2 -2
  44. elasticsearch/_sync/client/nodes.py +3 -5
  45. elasticsearch/_sync/client/project.py +67 -0
  46. elasticsearch/_sync/client/security.py +39 -0
  47. elasticsearch/_sync/client/shutdown.py +5 -15
  48. elasticsearch/_sync/client/simulate.py +8 -0
  49. elasticsearch/_sync/client/slm.py +1 -5
  50. elasticsearch/_sync/client/snapshot.py +20 -10
  51. elasticsearch/_sync/client/sql.py +7 -0
  52. elasticsearch/_sync/client/streams.py +185 -0
  53. elasticsearch/_sync/client/watcher.py +1 -5
  54. elasticsearch/_version.py +2 -1
  55. elasticsearch/client.py +4 -0
  56. elasticsearch/compat.py +30 -1
  57. elasticsearch/dsl/__init__.py +28 -0
  58. elasticsearch/dsl/_async/document.py +2 -1
  59. elasticsearch/dsl/_sync/document.py +2 -1
  60. elasticsearch/dsl/aggs.py +97 -0
  61. elasticsearch/dsl/document_base.py +53 -13
  62. elasticsearch/dsl/field.py +21 -2
  63. elasticsearch/dsl/pydantic.py +152 -0
  64. elasticsearch/dsl/query.py +5 -1
  65. elasticsearch/dsl/response/__init__.py +3 -0
  66. elasticsearch/dsl/search_base.py +5 -1
  67. elasticsearch/dsl/types.py +226 -14
  68. elasticsearch/esql/esql.py +331 -41
  69. elasticsearch/esql/functions.py +88 -0
  70. elasticsearch/helpers/__init__.py +10 -1
  71. elasticsearch/helpers/actions.py +106 -33
  72. {elasticsearch-9.1.1.dist-info → elasticsearch-9.2.0.dist-info}/METADATA +27 -5
  73. {elasticsearch-9.1.1.dist-info → elasticsearch-9.2.0.dist-info}/RECORD +76 -71
  74. {elasticsearch-9.1.1.dist-info → elasticsearch-9.2.0.dist-info}/WHEEL +0 -0
  75. {elasticsearch-9.1.1.dist-info → elasticsearch-9.2.0.dist-info}/licenses/LICENSE +0 -0
  76. {elasticsearch-9.1.1.dist-info → elasticsearch-9.2.0.dist-info}/licenses/NOTICE +0 -0
@@ -33,12 +33,18 @@ from typing import (
33
33
  Union,
34
34
  )
35
35
 
36
+ import sniffio
37
+ from anyio import create_memory_object_stream, create_task_group, move_on_after
38
+
36
39
  from ..exceptions import ApiError, NotFoundError, TransportError
37
40
  from ..helpers.actions import (
38
41
  _TYPE_BULK_ACTION,
39
42
  _TYPE_BULK_ACTION_BODY,
40
43
  _TYPE_BULK_ACTION_HEADER,
41
44
  _TYPE_BULK_ACTION_HEADER_AND_BODY,
45
+ _TYPE_BULK_ACTION_HEADER_WITH_META_AND_BODY,
46
+ _TYPE_BULK_ACTION_WITH_META,
47
+ BulkMeta,
42
48
  _ActionChunker,
43
49
  _process_bulk_chunk_error,
44
50
  _process_bulk_chunk_success,
@@ -53,10 +59,20 @@ logger = logging.getLogger("elasticsearch.helpers")
53
59
  T = TypeVar("T")
54
60
 
55
61
 
62
+ async def _sleep(seconds: float) -> None:
63
+ if sniffio.current_async_library() == "trio":
64
+ import trio
65
+
66
+ await trio.sleep(seconds)
67
+ else:
68
+ await asyncio.sleep(seconds)
69
+
70
+
56
71
  async def _chunk_actions(
57
- actions: AsyncIterable[_TYPE_BULK_ACTION_HEADER_AND_BODY],
72
+ actions: AsyncIterable[_TYPE_BULK_ACTION_HEADER_WITH_META_AND_BODY],
58
73
  chunk_size: int,
59
74
  max_chunk_bytes: int,
75
+ flush_after_seconds: Optional[float],
60
76
  serializer: Serializer,
61
77
  ) -> AsyncIterable[
62
78
  Tuple[
@@ -76,10 +92,46 @@ async def _chunk_actions(
76
92
  chunker = _ActionChunker(
77
93
  chunk_size=chunk_size, max_chunk_bytes=max_chunk_bytes, serializer=serializer
78
94
  )
79
- async for action, data in actions:
80
- ret = chunker.feed(action, data)
81
- if ret:
82
- yield ret
95
+
96
+ action: _TYPE_BULK_ACTION_WITH_META
97
+ data: _TYPE_BULK_ACTION_BODY
98
+ if not flush_after_seconds:
99
+ async for action, data in actions:
100
+ ret = chunker.feed(action, data)
101
+ if ret:
102
+ yield ret
103
+ else:
104
+ sender, receiver = create_memory_object_stream[
105
+ _TYPE_BULK_ACTION_HEADER_WITH_META_AND_BODY
106
+ ]()
107
+
108
+ async def get_items() -> None:
109
+ try:
110
+ async for item in actions:
111
+ await sender.send(item)
112
+ finally:
113
+ await sender.send((BulkMeta.done, None))
114
+
115
+ async with create_task_group() as tg:
116
+ tg.start_soon(get_items)
117
+
118
+ timeout: Optional[float] = flush_after_seconds
119
+ while True:
120
+ action = {}
121
+ data = None
122
+ with move_on_after(timeout) as scope:
123
+ action, data = await receiver.receive()
124
+ timeout = flush_after_seconds
125
+ if scope.cancelled_caught:
126
+ action, data = BulkMeta.flush, None
127
+ timeout = None
128
+
129
+ if action is BulkMeta.done:
130
+ break
131
+ ret = chunker.feed(action, data)
132
+ if ret:
133
+ yield ret
134
+
83
135
  ret = chunker.flush()
84
136
  if ret:
85
137
  yield ret
@@ -159,9 +211,13 @@ async def azip(
159
211
 
160
212
  async def async_streaming_bulk(
161
213
  client: AsyncElasticsearch,
162
- actions: Union[Iterable[_TYPE_BULK_ACTION], AsyncIterable[_TYPE_BULK_ACTION]],
214
+ actions: Union[
215
+ Iterable[_TYPE_BULK_ACTION_WITH_META],
216
+ AsyncIterable[_TYPE_BULK_ACTION_WITH_META],
217
+ ],
163
218
  chunk_size: int = 500,
164
219
  max_chunk_bytes: int = 100 * 1024 * 1024,
220
+ flush_after_seconds: Optional[float] = None,
165
221
  raise_on_error: bool = True,
166
222
  expand_action_callback: Callable[
167
223
  [_TYPE_BULK_ACTION], _TYPE_BULK_ACTION_HEADER_AND_BODY
@@ -194,6 +250,9 @@ async def async_streaming_bulk(
194
250
  :arg actions: iterable or async iterable containing the actions to be executed
195
251
  :arg chunk_size: number of docs in one chunk sent to es (default: 500)
196
252
  :arg max_chunk_bytes: the maximum size of the request in bytes (default: 100MB)
253
+ :arg flush_after_seconds: time in seconds after which a chunk is written even
254
+ if hasn't reached `chunk_size` or `max_chunk_bytes`. Set to 0 to not use a
255
+ timeout-based flush. (default: 0)
197
256
  :arg raise_on_error: raise ``BulkIndexError`` containing errors (as `.errors`)
198
257
  from the execution of the last chunk when some occur. By default we raise.
199
258
  :arg raise_on_exception: if ``False`` then don't propagate exceptions from
@@ -220,9 +279,14 @@ async def async_streaming_bulk(
220
279
  if isinstance(retry_on_status, int):
221
280
  retry_on_status = (retry_on_status,)
222
281
 
223
- async def map_actions() -> AsyncIterable[_TYPE_BULK_ACTION_HEADER_AND_BODY]:
282
+ async def map_actions() -> (
283
+ AsyncIterable[_TYPE_BULK_ACTION_HEADER_WITH_META_AND_BODY]
284
+ ):
224
285
  async for item in aiter(actions):
225
- yield expand_action_callback(item)
286
+ if isinstance(item, BulkMeta):
287
+ yield item, None
288
+ else:
289
+ yield expand_action_callback(item)
226
290
 
227
291
  serializer = client.transport.serializers.get_serializer("application/json")
228
292
 
@@ -234,7 +298,7 @@ async def async_streaming_bulk(
234
298
  ]
235
299
  bulk_actions: List[bytes]
236
300
  async for bulk_data, bulk_actions in _chunk_actions(
237
- map_actions(), chunk_size, max_chunk_bytes, serializer
301
+ map_actions(), chunk_size, max_chunk_bytes, flush_after_seconds, serializer
238
302
  ):
239
303
  for attempt in range(max_retries + 1):
240
304
  to_retry: List[bytes] = []
@@ -245,9 +309,7 @@ async def async_streaming_bulk(
245
309
  ]
246
310
  ] = []
247
311
  if attempt:
248
- await asyncio.sleep(
249
- min(max_backoff, initial_backoff * 2 ** (attempt - 1))
250
- )
312
+ await _sleep(min(max_backoff, initial_backoff * 2 ** (attempt - 1)))
251
313
 
252
314
  try:
253
315
  data: Union[