elasticsearch 8.19.1__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 (44) hide show
  1. elasticsearch/_async/client/__init__.py +27 -49
  2. elasticsearch/_async/client/cat.py +481 -25
  3. elasticsearch/_async/client/connector.py +3 -3
  4. elasticsearch/_async/client/fleet.py +1 -5
  5. elasticsearch/_async/client/graph.py +1 -5
  6. elasticsearch/_async/client/ilm.py +2 -10
  7. elasticsearch/_async/client/indices.py +158 -31
  8. elasticsearch/_async/client/inference.py +35 -121
  9. elasticsearch/_async/client/nodes.py +2 -2
  10. elasticsearch/_async/client/shutdown.py +5 -15
  11. elasticsearch/_async/client/slm.py +1 -5
  12. elasticsearch/_async/client/streams.py +185 -0
  13. elasticsearch/_async/client/watcher.py +1 -5
  14. elasticsearch/_async/helpers.py +58 -9
  15. elasticsearch/_sync/client/__init__.py +27 -49
  16. elasticsearch/_sync/client/cat.py +481 -25
  17. elasticsearch/_sync/client/connector.py +3 -3
  18. elasticsearch/_sync/client/fleet.py +1 -5
  19. elasticsearch/_sync/client/graph.py +1 -5
  20. elasticsearch/_sync/client/ilm.py +2 -10
  21. elasticsearch/_sync/client/indices.py +158 -31
  22. elasticsearch/_sync/client/inference.py +35 -121
  23. elasticsearch/_sync/client/nodes.py +2 -2
  24. elasticsearch/_sync/client/shutdown.py +5 -15
  25. elasticsearch/_sync/client/slm.py +1 -5
  26. elasticsearch/_sync/client/streams.py +185 -0
  27. elasticsearch/_sync/client/watcher.py +1 -5
  28. elasticsearch/_version.py +2 -1
  29. elasticsearch/client.py +2 -0
  30. elasticsearch/compat.py +45 -1
  31. elasticsearch/dsl/__init__.py +28 -0
  32. elasticsearch/dsl/aggs.py +97 -0
  33. elasticsearch/dsl/document_base.py +16 -1
  34. elasticsearch/dsl/field.py +12 -1
  35. elasticsearch/dsl/query.py +1 -1
  36. elasticsearch/dsl/response/__init__.py +3 -0
  37. elasticsearch/dsl/types.py +185 -9
  38. elasticsearch/helpers/__init__.py +10 -1
  39. elasticsearch/helpers/actions.py +106 -33
  40. {elasticsearch-8.19.1.dist-info → elasticsearch-8.19.2.dist-info}/METADATA +2 -2
  41. {elasticsearch-8.19.1.dist-info → elasticsearch-8.19.2.dist-info}/RECORD +44 -42
  42. {elasticsearch-8.19.1.dist-info → elasticsearch-8.19.2.dist-info}/WHEEL +0 -0
  43. {elasticsearch-8.19.1.dist-info → elasticsearch-8.19.2.dist-info}/licenses/LICENSE +0 -0
  44. {elasticsearch-8.19.1.dist-info → elasticsearch-8.19.2.dist-info}/licenses/NOTICE +0 -0
@@ -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] = []
@@ -75,6 +75,7 @@ from .slm import SlmClient
75
75
  from .snapshot import SnapshotClient
76
76
  from .sql import SqlClient
77
77
  from .ssl import SslClient
78
+ from .streams import StreamsClient
78
79
  from .synonyms import SynonymsClient
79
80
  from .tasks import TasksClient
80
81
  from .text_structure import TextStructureClient
@@ -470,6 +471,7 @@ class Elasticsearch(BaseClient):
470
471
  self.shutdown = ShutdownClient(self)
471
472
  self.sql = SqlClient(self)
472
473
  self.ssl = SslClient(self)
474
+ self.streams = StreamsClient(self)
473
475
  self.synonyms = SynonymsClient(self)
474
476
  self.text_structure = TextStructureClient(self)
475
477
  self.transform = TransformClient(self)
@@ -933,11 +935,7 @@ class Elasticsearch(BaseClient):
933
935
  if not __body:
934
936
  if id is not None:
935
937
  __body["id"] = id
936
- if not __body:
937
- __body = None # type: ignore[assignment]
938
- __headers = {"accept": "application/json"}
939
- if __body is not None:
940
- __headers["content-type"] = "application/json"
938
+ __headers = {"accept": "application/json", "content-type": "application/json"}
941
939
  return self.perform_request( # type: ignore[return-value]
942
940
  "DELETE",
943
941
  __path,
@@ -1010,8 +1008,8 @@ class Elasticsearch(BaseClient):
1010
1008
  This parameter can be used only when the `q` query string parameter is specified.
1011
1009
  :param analyzer: The analyzer to use for the query string. This parameter can
1012
1010
  be used only when the `q` query string parameter is specified.
1013
- :param default_operator: The default operator for query string query: `AND` or
1014
- `OR`. This parameter can be used only when the `q` query string parameter
1011
+ :param default_operator: The default operator for query string query: `and` or
1012
+ `or`. This parameter can be used only when the `q` query string parameter
1015
1013
  is specified.
1016
1014
  :param df: The field to use as a default when no field prefix is given in the
1017
1015
  query string. This parameter can be used only when the `q` query string parameter
@@ -1132,7 +1130,7 @@ class Elasticsearch(BaseClient):
1132
1130
  timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
1133
1131
  version: t.Optional[int] = None,
1134
1132
  version_type: t.Optional[
1135
- t.Union[str, t.Literal["external", "external_gte", "force", "internal"]]
1133
+ t.Union[str, t.Literal["external", "external_gte", "internal"]]
1136
1134
  ] = None,
1137
1135
  wait_for_active_shards: t.Optional[
1138
1136
  t.Union[int, t.Union[str, t.Literal["all", "index-setting"]]]
@@ -1311,7 +1309,7 @@ class Elasticsearch(BaseClient):
1311
1309
  timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
1312
1310
  version: t.Optional[int] = None,
1313
1311
  version_type: t.Optional[
1314
- t.Union[str, t.Literal["external", "external_gte", "force", "internal"]]
1312
+ t.Union[str, t.Literal["external", "external_gte", "internal"]]
1315
1313
  ] = None,
1316
1314
  wait_for_active_shards: t.Optional[
1317
1315
  t.Union[int, t.Union[str, t.Literal["all", "index-setting"]]]
@@ -1556,8 +1554,8 @@ class Elasticsearch(BaseClient):
1556
1554
  used only when the `q` query string parameter is specified.
1557
1555
  :param conflicts: What to do if delete by query hits version conflicts: `abort`
1558
1556
  or `proceed`.
1559
- :param default_operator: The default operator for query string query: `AND` or
1560
- `OR`. This parameter can be used only when the `q` query string parameter
1557
+ :param default_operator: The default operator for query string query: `and` or
1558
+ `or`. This parameter can be used only when the `q` query string parameter
1561
1559
  is specified.
1562
1560
  :param df: The field to use as default where no field prefix is given in the
1563
1561
  query string. This parameter can be used only when the `q` query string parameter
@@ -1851,7 +1849,7 @@ class Elasticsearch(BaseClient):
1851
1849
  stored_fields: t.Optional[t.Union[str, t.Sequence[str]]] = None,
1852
1850
  version: t.Optional[int] = None,
1853
1851
  version_type: t.Optional[
1854
- t.Union[str, t.Literal["external", "external_gte", "force", "internal"]]
1852
+ t.Union[str, t.Literal["external", "external_gte", "internal"]]
1855
1853
  ] = None,
1856
1854
  ) -> HeadApiResponse:
1857
1855
  """
@@ -1980,7 +1978,7 @@ class Elasticsearch(BaseClient):
1980
1978
  source_includes: t.Optional[t.Union[str, t.Sequence[str]]] = None,
1981
1979
  version: t.Optional[int] = None,
1982
1980
  version_type: t.Optional[
1983
- t.Union[str, t.Literal["external", "external_gte", "force", "internal"]]
1981
+ t.Union[str, t.Literal["external", "external_gte", "internal"]]
1984
1982
  ] = None,
1985
1983
  ) -> HeadApiResponse:
1986
1984
  """
@@ -2109,8 +2107,8 @@ class Elasticsearch(BaseClient):
2109
2107
  This parameter can be used only when the `q` query string parameter is specified.
2110
2108
  :param analyzer: The analyzer to use for the query string. This parameter can
2111
2109
  be used only when the `q` query string parameter is specified.
2112
- :param default_operator: The default operator for query string query: `AND` or
2113
- `OR`. This parameter can be used only when the `q` query string parameter
2110
+ :param default_operator: The default operator for query string query: `and` or
2111
+ `or`. This parameter can be used only when the `q` query string parameter
2114
2112
  is specified.
2115
2113
  :param df: The field to use as default where no field prefix is given in the
2116
2114
  query string. This parameter can be used only when the `q` query string parameter
@@ -2352,7 +2350,7 @@ class Elasticsearch(BaseClient):
2352
2350
  stored_fields: t.Optional[t.Union[str, t.Sequence[str]]] = None,
2353
2351
  version: t.Optional[int] = None,
2354
2352
  version_type: t.Optional[
2355
- t.Union[str, t.Literal["external", "external_gte", "force", "internal"]]
2353
+ t.Union[str, t.Literal["external", "external_gte", "internal"]]
2356
2354
  ] = None,
2357
2355
  ) -> ObjectApiResponse[t.Any]:
2358
2356
  """
@@ -2639,7 +2637,7 @@ class Elasticsearch(BaseClient):
2639
2637
  source_includes: t.Optional[t.Union[str, t.Sequence[str]]] = None,
2640
2638
  version: t.Optional[int] = None,
2641
2639
  version_type: t.Optional[
2642
- t.Union[str, t.Literal["external", "external_gte", "force", "internal"]]
2640
+ t.Union[str, t.Literal["external", "external_gte", "internal"]]
2643
2641
  ] = None,
2644
2642
  ) -> ObjectApiResponse[t.Any]:
2645
2643
  """
@@ -2819,7 +2817,7 @@ class Elasticsearch(BaseClient):
2819
2817
  timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
2820
2818
  version: t.Optional[int] = None,
2821
2819
  version_type: t.Optional[
2822
- t.Union[str, t.Literal["external", "external_gte", "force", "internal"]]
2820
+ t.Union[str, t.Literal["external", "external_gte", "internal"]]
2823
2821
  ] = None,
2824
2822
  wait_for_active_shards: t.Optional[
2825
2823
  t.Union[int, t.Union[str, t.Literal["all", "index-setting"]]]
@@ -3183,11 +3181,7 @@ class Elasticsearch(BaseClient):
3183
3181
  __body["_source"] = source
3184
3182
  if stored_fields is not None:
3185
3183
  __body["stored_fields"] = stored_fields
3186
- if not __body:
3187
- __body = None # type: ignore[assignment]
3188
- __headers = {"accept": "application/json"}
3189
- if __body is not None:
3190
- __headers["content-type"] = "application/json"
3184
+ __headers = {"accept": "application/json", "content-type": "application/json"}
3191
3185
  return self.perform_request( # type: ignore[return-value]
3192
3186
  "POST",
3193
3187
  __path,
@@ -3612,7 +3606,7 @@ class Elasticsearch(BaseClient):
3612
3606
  term_statistics: t.Optional[bool] = None,
3613
3607
  version: t.Optional[int] = None,
3614
3608
  version_type: t.Optional[
3615
- t.Union[str, t.Literal["external", "external_gte", "force", "internal"]]
3609
+ t.Union[str, t.Literal["external", "external_gte", "internal"]]
3616
3610
  ] = None,
3617
3611
  body: t.Optional[t.Dict[str, t.Any]] = None,
3618
3612
  ) -> ObjectApiResponse[t.Any]:
@@ -4022,7 +4016,7 @@ class Elasticsearch(BaseClient):
4022
4016
  )
4023
4017
 
4024
4018
  @_rewrite_parameters(
4025
- body_fields=("dest", "source", "conflicts", "max_docs", "script", "size"),
4019
+ body_fields=("dest", "source", "conflicts", "max_docs", "script"),
4026
4020
  )
4027
4021
  def reindex(
4028
4022
  self,
@@ -4040,7 +4034,6 @@ class Elasticsearch(BaseClient):
4040
4034
  require_alias: t.Optional[bool] = None,
4041
4035
  script: t.Optional[t.Mapping[str, t.Any]] = None,
4042
4036
  scroll: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
4043
- size: t.Optional[int] = None,
4044
4037
  slices: t.Optional[t.Union[int, t.Union[str, t.Literal["auto"]]]] = None,
4045
4038
  timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
4046
4039
  wait_for_active_shards: t.Optional[
@@ -4212,7 +4205,6 @@ class Elasticsearch(BaseClient):
4212
4205
  reindexing.
4213
4206
  :param scroll: The period of time that a consistent view of the index should
4214
4207
  be maintained for scrolled search.
4215
- :param size:
4216
4208
  :param slices: The number of slices this task should be divided into. It defaults
4217
4209
  to one slice, which means the task isn't sliced into subtasks. Reindex supports
4218
4210
  sliced scroll to parallelize the reindexing process. This parallelization
@@ -4277,8 +4269,6 @@ class Elasticsearch(BaseClient):
4277
4269
  __body["max_docs"] = max_docs
4278
4270
  if script is not None:
4279
4271
  __body["script"] = script
4280
- if size is not None:
4281
- __body["size"] = size
4282
4272
  __headers = {"accept": "application/json", "content-type": "application/json"}
4283
4273
  return self.perform_request( # type: ignore[return-value]
4284
4274
  "POST",
@@ -4405,11 +4395,7 @@ class Elasticsearch(BaseClient):
4405
4395
  __body["params"] = params
4406
4396
  if source is not None:
4407
4397
  __body["source"] = source
4408
- if not __body:
4409
- __body = None # type: ignore[assignment]
4410
- __headers = {"accept": "application/json"}
4411
- if __body is not None:
4412
- __headers["content-type"] = "application/json"
4398
+ __headers = {"accept": "application/json", "content-type": "application/json"}
4413
4399
  return self.perform_request( # type: ignore[return-value]
4414
4400
  "POST",
4415
4401
  __path,
@@ -4492,11 +4478,7 @@ class Elasticsearch(BaseClient):
4492
4478
  __body["context_setup"] = context_setup
4493
4479
  if script is not None:
4494
4480
  __body["script"] = script
4495
- if not __body:
4496
- __body = None # type: ignore[assignment]
4497
- __headers = {"accept": "application/json"}
4498
- if __body is not None:
4499
- __headers["content-type"] = "application/json"
4481
+ __headers = {"accept": "application/json", "content-type": "application/json"}
4500
4482
  return self.perform_request( # type: ignore[return-value]
4501
4483
  "POST",
4502
4484
  __path,
@@ -4772,8 +4754,8 @@ class Elasticsearch(BaseClient):
4772
4754
  node and the remote clusters are minimized when running cross-cluster search
4773
4755
  (CCS) requests.
4774
4756
  :param collapse: Collapses search results the values of the specified field.
4775
- :param default_operator: The default operator for the query string query: `AND`
4776
- or `OR`. This parameter can be used only when the `q` query string parameter
4757
+ :param default_operator: The default operator for the query string query: `and`
4758
+ or `or`. This parameter can be used only when the `q` query string parameter
4777
4759
  is specified.
4778
4760
  :param df: The field to use as a default when no field prefix is given in the
4779
4761
  query string. This parameter can be used only when the `q` query string parameter
@@ -5975,11 +5957,7 @@ class Elasticsearch(BaseClient):
5975
5957
  __body["string"] = string
5976
5958
  if timeout is not None:
5977
5959
  __body["timeout"] = timeout
5978
- if not __body:
5979
- __body = None # type: ignore[assignment]
5980
- __headers = {"accept": "application/json"}
5981
- if __body is not None:
5982
- __headers["content-type"] = "application/json"
5960
+ __headers = {"accept": "application/json", "content-type": "application/json"}
5983
5961
  return self.perform_request( # type: ignore[return-value]
5984
5962
  "POST",
5985
5963
  __path,
@@ -6029,7 +6007,7 @@ class Elasticsearch(BaseClient):
6029
6007
  term_statistics: t.Optional[bool] = None,
6030
6008
  version: t.Optional[int] = None,
6031
6009
  version_type: t.Optional[
6032
- t.Union[str, t.Literal["external", "external_gte", "force", "internal"]]
6010
+ t.Union[str, t.Literal["external", "external_gte", "internal"]]
6033
6011
  ] = None,
6034
6012
  body: t.Optional[t.Dict[str, t.Any]] = None,
6035
6013
  ) -> ObjectApiResponse[t.Any]:
@@ -6495,8 +6473,8 @@ class Elasticsearch(BaseClient):
6495
6473
  be used only when the `q` query string parameter is specified.
6496
6474
  :param conflicts: The preferred behavior when update by query hits version conflicts:
6497
6475
  `abort` or `proceed`.
6498
- :param default_operator: The default operator for query string query: `AND` or
6499
- `OR`. This parameter can be used only when the `q` query string parameter
6476
+ :param default_operator: The default operator for query string query: `and` or
6477
+ `or`. This parameter can be used only when the `q` query string parameter
6500
6478
  is specified.
6501
6479
  :param df: The field to use as default where no field prefix is given in the
6502
6480
  query string. This parameter can be used only when the `q` query string parameter