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,268 @@
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 typing as t
19
+
20
+ from elastic_transport import ObjectApiResponse
21
+
22
+ from ._base import NamespacedClient
23
+ from .utils import SKIP_IN_PATH, _quote, _rewrite_parameters
24
+
25
+
26
+ class ShutdownClient(NamespacedClient):
27
+
28
+ @_rewrite_parameters()
29
+ def delete_node(
30
+ self,
31
+ *,
32
+ node_id: str,
33
+ error_trace: t.Optional[bool] = None,
34
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
35
+ human: t.Optional[bool] = None,
36
+ master_timeout: t.Optional[
37
+ t.Union[str, t.Literal["d", "h", "m", "micros", "ms", "nanos", "s"]]
38
+ ] = None,
39
+ pretty: t.Optional[bool] = None,
40
+ timeout: t.Optional[
41
+ t.Union[str, t.Literal["d", "h", "m", "micros", "ms", "nanos", "s"]]
42
+ ] = None,
43
+ ) -> ObjectApiResponse[t.Any]:
44
+ """
45
+ .. raw:: html
46
+
47
+ <p>Cancel node shutdown preparations.
48
+ Remove a node from the shutdown list so it can resume normal operations.
49
+ You must explicitly clear the shutdown request when a node rejoins the cluster or when a node has permanently left the cluster.
50
+ Shutdown requests are never removed automatically by Elasticsearch.</p>
51
+ <p>NOTE: This feature is designed for indirect use by Elastic Cloud, Elastic Cloud Enterprise, and Elastic Cloud on Kubernetes.
52
+ Direct use is not supported.</p>
53
+ <p>If the operator privileges feature is enabled, you must be an operator to use this API.</p>
54
+
55
+
56
+ `<https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-shutdown-delete-node>`_
57
+
58
+ :param node_id: The node id of node to be removed from the shutdown state
59
+ :param master_timeout: Period to wait for a connection to the master node. If
60
+ no response is received before the timeout expires, the request fails and
61
+ returns an error.
62
+ :param timeout: Period to wait for a response. If no response is received before
63
+ the timeout expires, the request fails and returns an error.
64
+ """
65
+ if node_id in SKIP_IN_PATH:
66
+ raise ValueError("Empty value passed for parameter 'node_id'")
67
+ __path_parts: t.Dict[str, str] = {"node_id": _quote(node_id)}
68
+ __path = f'/_nodes/{__path_parts["node_id"]}/shutdown'
69
+ __query: t.Dict[str, t.Any] = {}
70
+ if error_trace is not None:
71
+ __query["error_trace"] = error_trace
72
+ if filter_path is not None:
73
+ __query["filter_path"] = filter_path
74
+ if human is not None:
75
+ __query["human"] = human
76
+ if master_timeout is not None:
77
+ __query["master_timeout"] = master_timeout
78
+ if pretty is not None:
79
+ __query["pretty"] = pretty
80
+ if timeout is not None:
81
+ __query["timeout"] = timeout
82
+ __headers = {"accept": "application/json"}
83
+ return self.perform_request( # type: ignore[return-value]
84
+ "DELETE",
85
+ __path,
86
+ params=__query,
87
+ headers=__headers,
88
+ endpoint_id="shutdown.delete_node",
89
+ path_parts=__path_parts,
90
+ )
91
+
92
+ @_rewrite_parameters()
93
+ def get_node(
94
+ self,
95
+ *,
96
+ node_id: t.Optional[t.Union[str, t.Sequence[str]]] = None,
97
+ error_trace: t.Optional[bool] = None,
98
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
99
+ human: t.Optional[bool] = None,
100
+ master_timeout: t.Optional[
101
+ t.Union[str, t.Literal["d", "h", "m", "micros", "ms", "nanos", "s"]]
102
+ ] = None,
103
+ pretty: t.Optional[bool] = None,
104
+ ) -> ObjectApiResponse[t.Any]:
105
+ """
106
+ .. raw:: html
107
+
108
+ <p>Get the shutdown status.</p>
109
+ <p>Get information about nodes that are ready to be shut down, have shut down preparations still in progress, or have stalled.
110
+ The API returns status information for each part of the shut down process.</p>
111
+ <p>NOTE: This feature is designed for indirect use by Elasticsearch Service, Elastic Cloud Enterprise, and Elastic Cloud on Kubernetes. Direct use is not supported.</p>
112
+ <p>If the operator privileges feature is enabled, you must be an operator to use this API.</p>
113
+
114
+
115
+ `<https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-shutdown-get-node>`_
116
+
117
+ :param node_id: Which node for which to retrieve the shutdown status
118
+ :param master_timeout: Period to wait for a connection to the master node. If
119
+ no response is received before the timeout expires, the request fails and
120
+ returns an error.
121
+ """
122
+ __path_parts: t.Dict[str, str]
123
+ if node_id not in SKIP_IN_PATH:
124
+ __path_parts = {"node_id": _quote(node_id)}
125
+ __path = f'/_nodes/{__path_parts["node_id"]}/shutdown'
126
+ else:
127
+ __path_parts = {}
128
+ __path = "/_nodes/shutdown"
129
+ __query: t.Dict[str, t.Any] = {}
130
+ if error_trace is not None:
131
+ __query["error_trace"] = error_trace
132
+ if filter_path is not None:
133
+ __query["filter_path"] = filter_path
134
+ if human is not None:
135
+ __query["human"] = human
136
+ if master_timeout is not None:
137
+ __query["master_timeout"] = master_timeout
138
+ if pretty is not None:
139
+ __query["pretty"] = pretty
140
+ __headers = {"accept": "application/json"}
141
+ return self.perform_request( # type: ignore[return-value]
142
+ "GET",
143
+ __path,
144
+ params=__query,
145
+ headers=__headers,
146
+ endpoint_id="shutdown.get_node",
147
+ path_parts=__path_parts,
148
+ )
149
+
150
+ @_rewrite_parameters(
151
+ body_fields=("reason", "type", "allocation_delay", "target_node_name"),
152
+ )
153
+ def put_node(
154
+ self,
155
+ *,
156
+ node_id: str,
157
+ reason: t.Optional[str] = None,
158
+ type: t.Optional[
159
+ t.Union[str, t.Literal["remove", "replace", "restart"]]
160
+ ] = None,
161
+ allocation_delay: t.Optional[str] = None,
162
+ error_trace: t.Optional[bool] = None,
163
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
164
+ human: t.Optional[bool] = None,
165
+ master_timeout: t.Optional[
166
+ t.Union[str, t.Literal["d", "h", "m", "micros", "ms", "nanos", "s"]]
167
+ ] = None,
168
+ pretty: t.Optional[bool] = None,
169
+ target_node_name: t.Optional[str] = None,
170
+ timeout: t.Optional[
171
+ t.Union[str, t.Literal["d", "h", "m", "micros", "ms", "nanos", "s"]]
172
+ ] = None,
173
+ body: t.Optional[t.Dict[str, t.Any]] = None,
174
+ ) -> ObjectApiResponse[t.Any]:
175
+ """
176
+ .. raw:: html
177
+
178
+ <p>Prepare a node to be shut down.</p>
179
+ <p>NOTE: This feature is designed for indirect use by Elastic Cloud, Elastic Cloud Enterprise, and Elastic Cloud on Kubernetes. Direct use is not supported.</p>
180
+ <p>If you specify a node that is offline, it will be prepared for shut down when it rejoins the cluster.</p>
181
+ <p>If the operator privileges feature is enabled, you must be an operator to use this API.</p>
182
+ <p>The API migrates ongoing tasks and index shards to other nodes as needed to prepare a node to be restarted or shut down and removed from the cluster.
183
+ This ensures that Elasticsearch can be stopped safely with minimal disruption to the cluster.</p>
184
+ <p>You must specify the type of shutdown: <code>restart</code>, <code>remove</code>, or <code>replace</code>.
185
+ If a node is already being prepared for shutdown, you can use this API to change the shutdown type.</p>
186
+ <p>IMPORTANT: This API does NOT terminate the Elasticsearch process.
187
+ Monitor the node shutdown status to determine when it is safe to stop Elasticsearch.</p>
188
+
189
+
190
+ `<https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-shutdown-put-node>`_
191
+
192
+ :param node_id: The node identifier. This parameter is not validated against
193
+ the cluster's active nodes. This enables you to register a node for shut
194
+ down while it is offline. No error is thrown if you specify an invalid node
195
+ ID.
196
+ :param reason: A human-readable reason that the node is being shut down. This
197
+ field provides information for other cluster operators; it does not affect
198
+ the shut down process.
199
+ :param type: Valid values are restart, remove, or replace. Use restart when you
200
+ need to temporarily shut down a node to perform an upgrade, make configuration
201
+ changes, or perform other maintenance. Because the node is expected to rejoin
202
+ the cluster, data is not migrated off of the node. Use remove when you need
203
+ to permanently remove a node from the cluster. The node is not marked ready
204
+ for shutdown until data is migrated off of the node Use replace to do a 1:1
205
+ replacement of a node with another node. Certain allocation decisions will
206
+ be ignored (such as disk watermarks) in the interest of true replacement
207
+ of the source node with the target node. During a replace-type shutdown,
208
+ rollover and index creation may result in unassigned shards, and shrink may
209
+ fail until the replacement is complete.
210
+ :param allocation_delay: Only valid if type is restart. Controls how long Elasticsearch
211
+ will wait for the node to restart and join the cluster before reassigning
212
+ its shards to other nodes. This works the same as delaying allocation with
213
+ the index.unassigned.node_left.delayed_timeout setting. If you specify both
214
+ a restart allocation delay and an index-level allocation delay, the longer
215
+ of the two is used.
216
+ :param master_timeout: The period to wait for a connection to the master node.
217
+ If no response is received before the timeout expires, the request fails
218
+ and returns an error.
219
+ :param target_node_name: Only valid if type is replace. Specifies the name of
220
+ the node that is replacing the node being shut down. Shards from the shut
221
+ down node are only allowed to be allocated to the target node, and no other
222
+ data will be allocated to the target node. During relocation of data certain
223
+ allocation rules are ignored, such as disk watermarks or user attribute filtering
224
+ rules.
225
+ :param timeout: The period to wait for a response. If no response is received
226
+ before the timeout expires, the request fails and returns an error.
227
+ """
228
+ if node_id in SKIP_IN_PATH:
229
+ raise ValueError("Empty value passed for parameter 'node_id'")
230
+ if reason is None and body is None:
231
+ raise ValueError("Empty value passed for parameter 'reason'")
232
+ if type is None and body is None:
233
+ raise ValueError("Empty value passed for parameter 'type'")
234
+ __path_parts: t.Dict[str, str] = {"node_id": _quote(node_id)}
235
+ __path = f'/_nodes/{__path_parts["node_id"]}/shutdown'
236
+ __query: t.Dict[str, t.Any] = {}
237
+ __body: t.Dict[str, t.Any] = body if body is not None else {}
238
+ if error_trace is not None:
239
+ __query["error_trace"] = error_trace
240
+ if filter_path is not None:
241
+ __query["filter_path"] = filter_path
242
+ if human is not None:
243
+ __query["human"] = human
244
+ if master_timeout is not None:
245
+ __query["master_timeout"] = master_timeout
246
+ if pretty is not None:
247
+ __query["pretty"] = pretty
248
+ if timeout is not None:
249
+ __query["timeout"] = timeout
250
+ if not __body:
251
+ if reason is not None:
252
+ __body["reason"] = reason
253
+ if type is not None:
254
+ __body["type"] = type
255
+ if allocation_delay is not None:
256
+ __body["allocation_delay"] = allocation_delay
257
+ if target_node_name is not None:
258
+ __body["target_node_name"] = target_node_name
259
+ __headers = {"accept": "application/json", "content-type": "application/json"}
260
+ return self.perform_request( # type: ignore[return-value]
261
+ "PUT",
262
+ __path,
263
+ params=__query,
264
+ headers=__headers,
265
+ body=__body,
266
+ endpoint_id="shutdown.put_node",
267
+ path_parts=__path_parts,
268
+ )
@@ -0,0 +1,145 @@
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 typing as t
19
+
20
+ from elastic_transport import ObjectApiResponse
21
+
22
+ from ._base import NamespacedClient
23
+ from .utils import (
24
+ SKIP_IN_PATH,
25
+ Stability,
26
+ _quote,
27
+ _rewrite_parameters,
28
+ _stability_warning,
29
+ )
30
+
31
+
32
+ class SimulateClient(NamespacedClient):
33
+
34
+ @_rewrite_parameters(
35
+ body_fields=(
36
+ "docs",
37
+ "component_template_substitutions",
38
+ "index_template_substitutions",
39
+ "mapping_addition",
40
+ "pipeline_substitutions",
41
+ ),
42
+ )
43
+ @_stability_warning(Stability.EXPERIMENTAL)
44
+ def ingest(
45
+ self,
46
+ *,
47
+ docs: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
48
+ index: t.Optional[str] = None,
49
+ component_template_substitutions: t.Optional[
50
+ t.Mapping[str, t.Mapping[str, t.Any]]
51
+ ] = None,
52
+ error_trace: t.Optional[bool] = None,
53
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
54
+ human: t.Optional[bool] = None,
55
+ index_template_substitutions: t.Optional[
56
+ t.Mapping[str, t.Mapping[str, t.Any]]
57
+ ] = None,
58
+ mapping_addition: t.Optional[t.Mapping[str, t.Any]] = None,
59
+ pipeline: t.Optional[str] = None,
60
+ pipeline_substitutions: t.Optional[
61
+ t.Mapping[str, t.Mapping[str, t.Any]]
62
+ ] = None,
63
+ pretty: t.Optional[bool] = None,
64
+ body: t.Optional[t.Dict[str, t.Any]] = None,
65
+ ) -> ObjectApiResponse[t.Any]:
66
+ """
67
+ .. raw:: html
68
+
69
+ <p>Simulate data ingestion.
70
+ Run ingest pipelines against a set of provided documents, optionally with substitute pipeline definitions, to simulate ingesting data into an index.</p>
71
+ <p>This API is meant to be used for troubleshooting or pipeline development, as it does not actually index any data into Elasticsearch.</p>
72
+ <p>The API runs the default and final pipeline for that index against a set of documents provided in the body of the request.
73
+ If a pipeline contains a reroute processor, it follows that reroute processor to the new index, running that index's pipelines as well the same way that a non-simulated ingest would.
74
+ No data is indexed into Elasticsearch.
75
+ Instead, the transformed document is returned, along with the list of pipelines that have been run and the name of the index where the document would have been indexed if this were not a simulation.
76
+ The transformed document is validated against the mappings that would apply to this index, and any validation error is reported in the result.</p>
77
+ <p>This API differs from the simulate pipeline API in that you specify a single pipeline for that API, and it runs only that one pipeline.
78
+ The simulate pipeline API is more useful for developing a single pipeline, while the simulate ingest API is more useful for troubleshooting the interaction of the various pipelines that get applied when ingesting into an index.</p>
79
+ <p>By default, the pipeline definitions that are currently in the system are used.
80
+ However, you can supply substitute pipeline definitions in the body of the request.
81
+ These will be used in place of the pipeline definitions that are already in the system. This can be used to replace existing pipeline definitions or to create new ones. The pipeline substitutions are used only within this request.</p>
82
+
83
+
84
+ `<https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-simulate-ingest>`_
85
+
86
+ :param docs: Sample documents to test in the pipeline.
87
+ :param index: The index to simulate ingesting into. This value can be overridden
88
+ by specifying an index on each document. If you specify this parameter in
89
+ the request path, it is used for any documents that do not explicitly specify
90
+ an index argument.
91
+ :param component_template_substitutions: A map of component template names to
92
+ substitute component template definition objects.
93
+ :param index_template_substitutions: A map of index template names to substitute
94
+ index template definition objects.
95
+ :param mapping_addition:
96
+ :param pipeline: The pipeline to use as the default pipeline. This value can
97
+ be used to override the default pipeline of the index.
98
+ :param pipeline_substitutions: Pipelines to test. If you don’t specify the `pipeline`
99
+ request path parameter, this parameter is required. If you specify both this
100
+ and the request path parameter, the API only uses the request path parameter.
101
+ """
102
+ if docs is None and body is None:
103
+ raise ValueError("Empty value passed for parameter 'docs'")
104
+ __path_parts: t.Dict[str, str]
105
+ if index not in SKIP_IN_PATH:
106
+ __path_parts = {"index": _quote(index)}
107
+ __path = f'/_ingest/{__path_parts["index"]}/_simulate'
108
+ else:
109
+ __path_parts = {}
110
+ __path = "/_ingest/_simulate"
111
+ __query: t.Dict[str, t.Any] = {}
112
+ __body: t.Dict[str, t.Any] = body if body is not None else {}
113
+ if error_trace is not None:
114
+ __query["error_trace"] = error_trace
115
+ if filter_path is not None:
116
+ __query["filter_path"] = filter_path
117
+ if human is not None:
118
+ __query["human"] = human
119
+ if pipeline is not None:
120
+ __query["pipeline"] = pipeline
121
+ if pretty is not None:
122
+ __query["pretty"] = pretty
123
+ if not __body:
124
+ if docs is not None:
125
+ __body["docs"] = docs
126
+ if component_template_substitutions is not None:
127
+ __body["component_template_substitutions"] = (
128
+ component_template_substitutions
129
+ )
130
+ if index_template_substitutions is not None:
131
+ __body["index_template_substitutions"] = index_template_substitutions
132
+ if mapping_addition is not None:
133
+ __body["mapping_addition"] = mapping_addition
134
+ if pipeline_substitutions is not None:
135
+ __body["pipeline_substitutions"] = pipeline_substitutions
136
+ __headers = {"accept": "application/json", "content-type": "application/json"}
137
+ return self.perform_request( # type: ignore[return-value]
138
+ "POST",
139
+ __path,
140
+ params=__query,
141
+ headers=__headers,
142
+ body=__body,
143
+ endpoint_id="simulate.ingest",
144
+ path_parts=__path_parts,
145
+ )