elasticsearch 8.17.2__py3-none-any.whl → 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 (138) hide show
  1. elasticsearch/_async/client/__init__.py +192 -312
  2. elasticsearch/_async/client/_base.py +1 -2
  3. elasticsearch/_async/client/async_search.py +14 -14
  4. elasticsearch/_async/client/autoscaling.py +4 -4
  5. elasticsearch/_async/client/cat.py +26 -33
  6. elasticsearch/_async/client/ccr.py +186 -72
  7. elasticsearch/_async/client/cluster.py +42 -23
  8. elasticsearch/_async/client/connector.py +44 -30
  9. elasticsearch/_async/client/dangling_indices.py +3 -3
  10. elasticsearch/_async/client/enrich.py +26 -5
  11. elasticsearch/_async/client/eql.py +32 -4
  12. elasticsearch/_async/client/esql.py +64 -12
  13. elasticsearch/_async/client/features.py +12 -2
  14. elasticsearch/_async/client/fleet.py +23 -19
  15. elasticsearch/_async/client/graph.py +1 -1
  16. elasticsearch/_async/client/ilm.py +30 -22
  17. elasticsearch/_async/client/indices.py +435 -231
  18. elasticsearch/_async/client/inference.py +1906 -61
  19. elasticsearch/_async/client/ingest.py +32 -38
  20. elasticsearch/_async/client/license.py +51 -16
  21. elasticsearch/_async/client/logstash.py +3 -3
  22. elasticsearch/_async/client/migration.py +3 -3
  23. elasticsearch/_async/client/ml.py +145 -121
  24. elasticsearch/_async/client/monitoring.py +1 -1
  25. elasticsearch/_async/client/nodes.py +10 -28
  26. elasticsearch/_async/client/query_rules.py +8 -8
  27. elasticsearch/_async/client/rollup.py +8 -8
  28. elasticsearch/_async/client/search_application.py +13 -13
  29. elasticsearch/_async/client/searchable_snapshots.py +4 -4
  30. elasticsearch/_async/client/security.py +78 -75
  31. elasticsearch/_async/client/shutdown.py +3 -10
  32. elasticsearch/_async/client/simulate.py +6 -6
  33. elasticsearch/_async/client/slm.py +9 -9
  34. elasticsearch/_async/client/snapshot.py +280 -134
  35. elasticsearch/_async/client/sql.py +6 -6
  36. elasticsearch/_async/client/ssl.py +1 -1
  37. elasticsearch/_async/client/synonyms.py +7 -7
  38. elasticsearch/_async/client/tasks.py +3 -9
  39. elasticsearch/_async/client/text_structure.py +4 -4
  40. elasticsearch/_async/client/transform.py +30 -28
  41. elasticsearch/_async/client/watcher.py +23 -15
  42. elasticsearch/_async/client/xpack.py +2 -2
  43. elasticsearch/_async/helpers.py +0 -1
  44. elasticsearch/_sync/client/__init__.py +192 -312
  45. elasticsearch/_sync/client/_base.py +1 -2
  46. elasticsearch/_sync/client/async_search.py +14 -14
  47. elasticsearch/_sync/client/autoscaling.py +4 -4
  48. elasticsearch/_sync/client/cat.py +26 -33
  49. elasticsearch/_sync/client/ccr.py +186 -72
  50. elasticsearch/_sync/client/cluster.py +42 -23
  51. elasticsearch/_sync/client/connector.py +44 -30
  52. elasticsearch/_sync/client/dangling_indices.py +3 -3
  53. elasticsearch/_sync/client/enrich.py +26 -5
  54. elasticsearch/_sync/client/eql.py +32 -4
  55. elasticsearch/_sync/client/esql.py +64 -12
  56. elasticsearch/_sync/client/features.py +12 -2
  57. elasticsearch/_sync/client/fleet.py +23 -19
  58. elasticsearch/_sync/client/graph.py +1 -1
  59. elasticsearch/_sync/client/ilm.py +30 -22
  60. elasticsearch/_sync/client/indices.py +435 -231
  61. elasticsearch/_sync/client/inference.py +1906 -61
  62. elasticsearch/_sync/client/ingest.py +32 -38
  63. elasticsearch/_sync/client/license.py +51 -16
  64. elasticsearch/_sync/client/logstash.py +3 -3
  65. elasticsearch/_sync/client/migration.py +3 -3
  66. elasticsearch/_sync/client/ml.py +145 -121
  67. elasticsearch/_sync/client/monitoring.py +1 -1
  68. elasticsearch/_sync/client/nodes.py +10 -28
  69. elasticsearch/_sync/client/query_rules.py +8 -8
  70. elasticsearch/_sync/client/rollup.py +8 -8
  71. elasticsearch/_sync/client/search_application.py +13 -13
  72. elasticsearch/_sync/client/searchable_snapshots.py +4 -4
  73. elasticsearch/_sync/client/security.py +78 -75
  74. elasticsearch/_sync/client/shutdown.py +3 -10
  75. elasticsearch/_sync/client/simulate.py +6 -6
  76. elasticsearch/_sync/client/slm.py +9 -9
  77. elasticsearch/_sync/client/snapshot.py +280 -134
  78. elasticsearch/_sync/client/sql.py +6 -6
  79. elasticsearch/_sync/client/ssl.py +1 -1
  80. elasticsearch/_sync/client/synonyms.py +7 -7
  81. elasticsearch/_sync/client/tasks.py +3 -9
  82. elasticsearch/_sync/client/text_structure.py +4 -4
  83. elasticsearch/_sync/client/transform.py +30 -28
  84. elasticsearch/_sync/client/utils.py +0 -40
  85. elasticsearch/_sync/client/watcher.py +23 -15
  86. elasticsearch/_sync/client/xpack.py +2 -2
  87. elasticsearch/_version.py +1 -1
  88. elasticsearch/dsl/__init__.py +203 -0
  89. elasticsearch/dsl/_async/__init__.py +16 -0
  90. elasticsearch/dsl/_async/document.py +522 -0
  91. elasticsearch/dsl/_async/faceted_search.py +50 -0
  92. elasticsearch/dsl/_async/index.py +639 -0
  93. elasticsearch/dsl/_async/mapping.py +49 -0
  94. elasticsearch/dsl/_async/search.py +237 -0
  95. elasticsearch/dsl/_async/update_by_query.py +47 -0
  96. elasticsearch/dsl/_sync/__init__.py +16 -0
  97. elasticsearch/dsl/_sync/document.py +514 -0
  98. elasticsearch/dsl/_sync/faceted_search.py +50 -0
  99. elasticsearch/dsl/_sync/index.py +597 -0
  100. elasticsearch/dsl/_sync/mapping.py +49 -0
  101. elasticsearch/dsl/_sync/search.py +230 -0
  102. elasticsearch/dsl/_sync/update_by_query.py +45 -0
  103. elasticsearch/dsl/aggs.py +3734 -0
  104. elasticsearch/dsl/analysis.py +341 -0
  105. elasticsearch/dsl/async_connections.py +37 -0
  106. elasticsearch/dsl/connections.py +142 -0
  107. elasticsearch/dsl/document.py +20 -0
  108. elasticsearch/dsl/document_base.py +444 -0
  109. elasticsearch/dsl/exceptions.py +32 -0
  110. elasticsearch/dsl/faceted_search.py +28 -0
  111. elasticsearch/dsl/faceted_search_base.py +489 -0
  112. elasticsearch/dsl/field.py +4392 -0
  113. elasticsearch/dsl/function.py +180 -0
  114. elasticsearch/dsl/index.py +23 -0
  115. elasticsearch/dsl/index_base.py +178 -0
  116. elasticsearch/dsl/mapping.py +19 -0
  117. elasticsearch/dsl/mapping_base.py +219 -0
  118. elasticsearch/dsl/query.py +2822 -0
  119. elasticsearch/dsl/response/__init__.py +388 -0
  120. elasticsearch/dsl/response/aggs.py +100 -0
  121. elasticsearch/dsl/response/hit.py +53 -0
  122. elasticsearch/dsl/search.py +20 -0
  123. elasticsearch/dsl/search_base.py +1053 -0
  124. elasticsearch/dsl/serializer.py +34 -0
  125. elasticsearch/dsl/types.py +6453 -0
  126. elasticsearch/dsl/update_by_query.py +19 -0
  127. elasticsearch/dsl/update_by_query_base.py +149 -0
  128. elasticsearch/dsl/utils.py +687 -0
  129. elasticsearch/dsl/wrappers.py +144 -0
  130. elasticsearch/helpers/vectorstore/_async/strategies.py +12 -12
  131. elasticsearch/helpers/vectorstore/_sync/strategies.py +12 -12
  132. {elasticsearch-8.17.2.dist-info → elasticsearch-9.0.0.dist-info}/METADATA +12 -15
  133. elasticsearch-9.0.0.dist-info/RECORD +160 -0
  134. elasticsearch/transport.py +0 -57
  135. elasticsearch-8.17.2.dist-info/RECORD +0 -119
  136. {elasticsearch-8.17.2.dist-info → elasticsearch-9.0.0.dist-info}/WHEEL +0 -0
  137. {elasticsearch-8.17.2.dist-info → elasticsearch-9.0.0.dist-info}/licenses/LICENSE +0 -0
  138. {elasticsearch-8.17.2.dist-info → elasticsearch-9.0.0.dist-info}/licenses/NOTICE +0 -0
@@ -0,0 +1,237 @@
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 contextlib
19
+ from typing import (
20
+ TYPE_CHECKING,
21
+ Any,
22
+ AsyncIterator,
23
+ Dict,
24
+ Iterator,
25
+ List,
26
+ Optional,
27
+ cast,
28
+ )
29
+
30
+ from typing_extensions import Self
31
+
32
+ from elasticsearch.exceptions import ApiError
33
+ from elasticsearch.helpers import async_scan
34
+
35
+ from ..async_connections import get_connection
36
+ from ..response import Response
37
+ from ..search_base import MultiSearchBase, SearchBase
38
+ from ..utils import _R, AsyncUsingType, AttrDict
39
+
40
+
41
+ class AsyncSearch(SearchBase[_R]):
42
+ _using: AsyncUsingType
43
+
44
+ def __aiter__(self) -> AsyncIterator[_R]:
45
+ """
46
+ Iterate over the hits.
47
+ """
48
+
49
+ class ResultsIterator(AsyncIterator[_R]):
50
+ def __init__(self, search: AsyncSearch[_R]):
51
+ self.search = search
52
+ self.iterator: Optional[Iterator[_R]] = None
53
+
54
+ async def __anext__(self) -> _R:
55
+ if self.iterator is None:
56
+ self.iterator = iter(await self.search.execute())
57
+ try:
58
+ return next(self.iterator)
59
+ except StopIteration:
60
+ raise StopAsyncIteration()
61
+
62
+ return ResultsIterator(self)
63
+
64
+ async def count(self) -> int:
65
+ """
66
+ Return the number of hits matching the query and filters. Note that
67
+ only the actual number is returned.
68
+ """
69
+ if hasattr(self, "_response") and self._response.hits.total.relation == "eq": # type: ignore[attr-defined]
70
+ return cast(int, self._response.hits.total.value) # type: ignore[attr-defined]
71
+
72
+ es = get_connection(self._using)
73
+
74
+ d = self.to_dict(count=True)
75
+ # TODO: failed shards detection
76
+ resp = await es.count(
77
+ index=self._index,
78
+ query=cast(Optional[Dict[str, Any]], d.get("query", None)),
79
+ **self._params,
80
+ )
81
+
82
+ return cast(int, resp["count"])
83
+
84
+ async def execute(self, ignore_cache: bool = False) -> Response[_R]:
85
+ """
86
+ Execute the search and return an instance of ``Response`` wrapping all
87
+ the data.
88
+
89
+ :arg ignore_cache: if set to ``True``, consecutive calls will hit
90
+ ES, while cached result will be ignored. Defaults to `False`
91
+ """
92
+ if ignore_cache or not hasattr(self, "_response"):
93
+ es = get_connection(self._using)
94
+
95
+ self._response = self._response_class(
96
+ self,
97
+ (
98
+ await es.search(
99
+ index=self._index, body=self.to_dict(), **self._params
100
+ )
101
+ ).body,
102
+ )
103
+ return self._response
104
+
105
+ async def scan(self) -> AsyncIterator[_R]:
106
+ """
107
+ Turn the search into a scan search and return a generator that will
108
+ iterate over all the documents matching the query.
109
+
110
+ Use the ``params`` method to specify any additional arguments you wish to
111
+ pass to the underlying ``scan`` helper from ``elasticsearch-py`` -
112
+ https://elasticsearch-py.readthedocs.io/en/latest/helpers.html#scan
113
+
114
+ The ``iterate()`` method should be preferred, as it provides similar
115
+ functionality using an Elasticsearch point in time.
116
+ """
117
+ es = get_connection(self._using)
118
+
119
+ async for hit in async_scan(
120
+ es, query=self.to_dict(), index=self._index, **self._params
121
+ ):
122
+ yield self._get_result(cast(AttrDict[Any], hit))
123
+
124
+ async def delete(self) -> AttrDict[Any]:
125
+ """
126
+ ``delete()`` executes the query by delegating to ``delete_by_query()``.
127
+
128
+ Use the ``params`` method to specify any additional arguments you wish to
129
+ pass to the underlying ``delete_by_query`` helper from ``elasticsearch-py`` -
130
+ https://elasticsearch-py.readthedocs.io/en/latest/api/elasticsearch.html#elasticsearch.Elasticsearch.delete_by_query
131
+ """
132
+
133
+ es = get_connection(self._using)
134
+ assert self._index is not None
135
+
136
+ return AttrDict(
137
+ cast(
138
+ Dict[str, Any],
139
+ await es.delete_by_query(
140
+ index=self._index, body=self.to_dict(), **self._params
141
+ ),
142
+ )
143
+ )
144
+
145
+ @contextlib.asynccontextmanager
146
+ async def point_in_time(self, keep_alive: str = "1m") -> AsyncIterator[Self]:
147
+ """
148
+ Open a point in time (pit) that can be used across several searches.
149
+
150
+ This method implements a context manager that returns a search object
151
+ configured to operate within the created pit.
152
+
153
+ :arg keep_alive: the time to live for the point in time, renewed with each search request
154
+ """
155
+ es = get_connection(self._using)
156
+
157
+ pit = await es.open_point_in_time(
158
+ index=self._index or "*", keep_alive=keep_alive
159
+ )
160
+ search = self.index().extra(pit={"id": pit["id"], "keep_alive": keep_alive})
161
+ if not search._sort:
162
+ search = search.sort("_shard_doc")
163
+ yield search
164
+ await es.close_point_in_time(id=pit["id"])
165
+
166
+ async def iterate(self, keep_alive: str = "1m") -> AsyncIterator[_R]:
167
+ """
168
+ Return a generator that iterates over all the documents matching the query.
169
+
170
+ This method uses a point in time to provide consistent results even when
171
+ the index is changing. It should be preferred over ``scan()``.
172
+
173
+ :arg keep_alive: the time to live for the point in time, renewed with each new search request
174
+ """
175
+ async with self.point_in_time(keep_alive=keep_alive) as s:
176
+ while True:
177
+ r = await s.execute()
178
+ for hit in r:
179
+ yield hit
180
+ if len(r.hits) == 0:
181
+ break
182
+ s = s.search_after()
183
+
184
+
185
+ class AsyncMultiSearch(MultiSearchBase[_R]):
186
+ """
187
+ Combine multiple :class:`~elasticsearch.dsl.Search` objects into a single
188
+ request.
189
+ """
190
+
191
+ _using: AsyncUsingType
192
+
193
+ if TYPE_CHECKING:
194
+
195
+ def add(self, search: AsyncSearch[_R]) -> Self: ... # type: ignore[override]
196
+
197
+ async def execute(
198
+ self, ignore_cache: bool = False, raise_on_error: bool = True
199
+ ) -> List[Response[_R]]:
200
+ """
201
+ Execute the multi search request and return a list of search results.
202
+ """
203
+ if ignore_cache or not hasattr(self, "_response"):
204
+ es = get_connection(self._using)
205
+
206
+ responses = await es.msearch(
207
+ index=self._index, body=self.to_dict(), **self._params
208
+ )
209
+
210
+ out: List[Response[_R]] = []
211
+ for s, r in zip(self._searches, responses["responses"]):
212
+ if r.get("error", False):
213
+ if raise_on_error:
214
+ raise ApiError("N/A", meta=responses.meta, body=r)
215
+ r = None
216
+ else:
217
+ r = Response(s, r)
218
+ out.append(r)
219
+
220
+ self._response = out
221
+
222
+ return self._response
223
+
224
+
225
+ class AsyncEmptySearch(AsyncSearch[_R]):
226
+ async def count(self) -> int:
227
+ return 0
228
+
229
+ async def execute(self, ignore_cache: bool = False) -> Response[_R]:
230
+ return self._response_class(self, {"hits": {"total": 0, "hits": []}})
231
+
232
+ async def scan(self) -> AsyncIterator[_R]:
233
+ return
234
+ yield # a bit strange, but this forces an empty generator function
235
+
236
+ async def delete(self) -> AttrDict[Any]:
237
+ return AttrDict[Any]({})
@@ -0,0 +1,47 @@
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
+ from typing import TYPE_CHECKING
19
+
20
+ from ..async_connections import get_connection
21
+ from ..update_by_query_base import UpdateByQueryBase
22
+ from ..utils import _R, AsyncUsingType
23
+
24
+ if TYPE_CHECKING:
25
+ from ..response import UpdateByQueryResponse
26
+
27
+
28
+ class AsyncUpdateByQuery(UpdateByQueryBase[_R]):
29
+ _using: AsyncUsingType
30
+
31
+ async def execute(self) -> "UpdateByQueryResponse[_R]":
32
+ """
33
+ Execute the search and return an instance of ``Response`` wrapping all
34
+ the data.
35
+ """
36
+ es = get_connection(self._using)
37
+ assert self._index is not None
38
+
39
+ self._response = self._response_class(
40
+ self,
41
+ (
42
+ await es.update_by_query(
43
+ index=self._index, **self.to_dict(), **self._params
44
+ )
45
+ ).body,
46
+ )
47
+ return self._response
@@ -0,0 +1,16 @@
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.