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,485 @@
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 QueryRulesClient(NamespacedClient):
27
+
28
+ @_rewrite_parameters()
29
+ def delete_rule(
30
+ self,
31
+ *,
32
+ ruleset_id: str,
33
+ rule_id: str,
34
+ error_trace: t.Optional[bool] = None,
35
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
36
+ human: t.Optional[bool] = None,
37
+ pretty: t.Optional[bool] = None,
38
+ ) -> ObjectApiResponse[t.Any]:
39
+ """
40
+ .. raw:: html
41
+
42
+ <p>Delete a query rule.
43
+ Delete a query rule within a query ruleset.
44
+ This is a destructive action that is only recoverable by re-adding the same rule with the create or update query rule API.</p>
45
+
46
+
47
+ `<https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-query-rules-delete-rule>`_
48
+
49
+ :param ruleset_id: The unique identifier of the query ruleset containing the
50
+ rule to delete
51
+ :param rule_id: The unique identifier of the query rule within the specified
52
+ ruleset to delete
53
+ """
54
+ if ruleset_id in SKIP_IN_PATH:
55
+ raise ValueError("Empty value passed for parameter 'ruleset_id'")
56
+ if rule_id in SKIP_IN_PATH:
57
+ raise ValueError("Empty value passed for parameter 'rule_id'")
58
+ __path_parts: t.Dict[str, str] = {
59
+ "ruleset_id": _quote(ruleset_id),
60
+ "rule_id": _quote(rule_id),
61
+ }
62
+ __path = f'/_query_rules/{__path_parts["ruleset_id"]}/_rule/{__path_parts["rule_id"]}'
63
+ __query: t.Dict[str, t.Any] = {}
64
+ if error_trace is not None:
65
+ __query["error_trace"] = error_trace
66
+ if filter_path is not None:
67
+ __query["filter_path"] = filter_path
68
+ if human is not None:
69
+ __query["human"] = human
70
+ if pretty is not None:
71
+ __query["pretty"] = pretty
72
+ __headers = {"accept": "application/json"}
73
+ return self.perform_request( # type: ignore[return-value]
74
+ "DELETE",
75
+ __path,
76
+ params=__query,
77
+ headers=__headers,
78
+ endpoint_id="query_rules.delete_rule",
79
+ path_parts=__path_parts,
80
+ )
81
+
82
+ @_rewrite_parameters()
83
+ def delete_ruleset(
84
+ self,
85
+ *,
86
+ ruleset_id: str,
87
+ error_trace: t.Optional[bool] = None,
88
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
89
+ human: t.Optional[bool] = None,
90
+ pretty: t.Optional[bool] = None,
91
+ ) -> ObjectApiResponse[t.Any]:
92
+ """
93
+ .. raw:: html
94
+
95
+ <p>Delete a query ruleset.
96
+ Remove a query ruleset and its associated data.
97
+ This is a destructive action that is not recoverable.</p>
98
+
99
+
100
+ `<https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-query-rules-delete-ruleset>`_
101
+
102
+ :param ruleset_id: The unique identifier of the query ruleset to delete
103
+ """
104
+ if ruleset_id in SKIP_IN_PATH:
105
+ raise ValueError("Empty value passed for parameter 'ruleset_id'")
106
+ __path_parts: t.Dict[str, str] = {"ruleset_id": _quote(ruleset_id)}
107
+ __path = f'/_query_rules/{__path_parts["ruleset_id"]}'
108
+ __query: t.Dict[str, t.Any] = {}
109
+ if error_trace is not None:
110
+ __query["error_trace"] = error_trace
111
+ if filter_path is not None:
112
+ __query["filter_path"] = filter_path
113
+ if human is not None:
114
+ __query["human"] = human
115
+ if pretty is not None:
116
+ __query["pretty"] = pretty
117
+ __headers = {"accept": "application/json"}
118
+ return self.perform_request( # type: ignore[return-value]
119
+ "DELETE",
120
+ __path,
121
+ params=__query,
122
+ headers=__headers,
123
+ endpoint_id="query_rules.delete_ruleset",
124
+ path_parts=__path_parts,
125
+ )
126
+
127
+ @_rewrite_parameters()
128
+ def get_rule(
129
+ self,
130
+ *,
131
+ ruleset_id: str,
132
+ rule_id: str,
133
+ error_trace: t.Optional[bool] = None,
134
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
135
+ human: t.Optional[bool] = None,
136
+ pretty: t.Optional[bool] = None,
137
+ ) -> ObjectApiResponse[t.Any]:
138
+ """
139
+ .. raw:: html
140
+
141
+ <p>Get a query rule.
142
+ Get details about a query rule within a query ruleset.</p>
143
+
144
+
145
+ `<https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-query-rules-get-rule>`_
146
+
147
+ :param ruleset_id: The unique identifier of the query ruleset containing the
148
+ rule to retrieve
149
+ :param rule_id: The unique identifier of the query rule within the specified
150
+ ruleset to retrieve
151
+ """
152
+ if ruleset_id in SKIP_IN_PATH:
153
+ raise ValueError("Empty value passed for parameter 'ruleset_id'")
154
+ if rule_id in SKIP_IN_PATH:
155
+ raise ValueError("Empty value passed for parameter 'rule_id'")
156
+ __path_parts: t.Dict[str, str] = {
157
+ "ruleset_id": _quote(ruleset_id),
158
+ "rule_id": _quote(rule_id),
159
+ }
160
+ __path = f'/_query_rules/{__path_parts["ruleset_id"]}/_rule/{__path_parts["rule_id"]}'
161
+ __query: t.Dict[str, t.Any] = {}
162
+ if error_trace is not None:
163
+ __query["error_trace"] = error_trace
164
+ if filter_path is not None:
165
+ __query["filter_path"] = filter_path
166
+ if human is not None:
167
+ __query["human"] = human
168
+ if pretty is not None:
169
+ __query["pretty"] = pretty
170
+ __headers = {"accept": "application/json"}
171
+ return self.perform_request( # type: ignore[return-value]
172
+ "GET",
173
+ __path,
174
+ params=__query,
175
+ headers=__headers,
176
+ endpoint_id="query_rules.get_rule",
177
+ path_parts=__path_parts,
178
+ )
179
+
180
+ @_rewrite_parameters()
181
+ def get_ruleset(
182
+ self,
183
+ *,
184
+ ruleset_id: str,
185
+ error_trace: t.Optional[bool] = None,
186
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
187
+ human: t.Optional[bool] = None,
188
+ pretty: t.Optional[bool] = None,
189
+ ) -> ObjectApiResponse[t.Any]:
190
+ """
191
+ .. raw:: html
192
+
193
+ <p>Get a query ruleset.
194
+ Get details about a query ruleset.</p>
195
+
196
+
197
+ `<https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-query-rules-get-ruleset>`_
198
+
199
+ :param ruleset_id: The unique identifier of the query ruleset
200
+ """
201
+ if ruleset_id in SKIP_IN_PATH:
202
+ raise ValueError("Empty value passed for parameter 'ruleset_id'")
203
+ __path_parts: t.Dict[str, str] = {"ruleset_id": _quote(ruleset_id)}
204
+ __path = f'/_query_rules/{__path_parts["ruleset_id"]}'
205
+ __query: t.Dict[str, t.Any] = {}
206
+ if error_trace is not None:
207
+ __query["error_trace"] = error_trace
208
+ if filter_path is not None:
209
+ __query["filter_path"] = filter_path
210
+ if human is not None:
211
+ __query["human"] = human
212
+ if pretty is not None:
213
+ __query["pretty"] = pretty
214
+ __headers = {"accept": "application/json"}
215
+ return self.perform_request( # type: ignore[return-value]
216
+ "GET",
217
+ __path,
218
+ params=__query,
219
+ headers=__headers,
220
+ endpoint_id="query_rules.get_ruleset",
221
+ path_parts=__path_parts,
222
+ )
223
+
224
+ @_rewrite_parameters(
225
+ parameter_aliases={"from": "from_"},
226
+ )
227
+ def list_rulesets(
228
+ self,
229
+ *,
230
+ error_trace: t.Optional[bool] = None,
231
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
232
+ from_: t.Optional[int] = None,
233
+ human: t.Optional[bool] = None,
234
+ pretty: t.Optional[bool] = None,
235
+ size: t.Optional[int] = None,
236
+ ) -> ObjectApiResponse[t.Any]:
237
+ """
238
+ .. raw:: html
239
+
240
+ <p>Get all query rulesets.
241
+ Get summarized information about the query rulesets.</p>
242
+
243
+
244
+ `<https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-query-rules-list-rulesets>`_
245
+
246
+ :param from_: The offset from the first result to fetch.
247
+ :param size: The maximum number of results to retrieve.
248
+ """
249
+ __path_parts: t.Dict[str, str] = {}
250
+ __path = "/_query_rules"
251
+ __query: t.Dict[str, t.Any] = {}
252
+ if error_trace is not None:
253
+ __query["error_trace"] = error_trace
254
+ if filter_path is not None:
255
+ __query["filter_path"] = filter_path
256
+ if from_ is not None:
257
+ __query["from"] = from_
258
+ if human is not None:
259
+ __query["human"] = human
260
+ if pretty is not None:
261
+ __query["pretty"] = pretty
262
+ if size is not None:
263
+ __query["size"] = size
264
+ __headers = {"accept": "application/json"}
265
+ return self.perform_request( # type: ignore[return-value]
266
+ "GET",
267
+ __path,
268
+ params=__query,
269
+ headers=__headers,
270
+ endpoint_id="query_rules.list_rulesets",
271
+ path_parts=__path_parts,
272
+ )
273
+
274
+ @_rewrite_parameters(
275
+ body_fields=("actions", "criteria", "type", "priority"),
276
+ )
277
+ def put_rule(
278
+ self,
279
+ *,
280
+ ruleset_id: str,
281
+ rule_id: str,
282
+ actions: t.Optional[t.Mapping[str, t.Any]] = None,
283
+ criteria: t.Optional[
284
+ t.Union[t.Mapping[str, t.Any], t.Sequence[t.Mapping[str, t.Any]]]
285
+ ] = None,
286
+ type: t.Optional[t.Union[str, t.Literal["exclude", "pinned"]]] = None,
287
+ error_trace: t.Optional[bool] = None,
288
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
289
+ human: t.Optional[bool] = None,
290
+ pretty: t.Optional[bool] = None,
291
+ priority: t.Optional[int] = None,
292
+ body: t.Optional[t.Dict[str, t.Any]] = None,
293
+ ) -> ObjectApiResponse[t.Any]:
294
+ """
295
+ .. raw:: html
296
+
297
+ <p>Create or update a query rule.
298
+ Create or update a query rule within a query ruleset.</p>
299
+ <p>IMPORTANT: Due to limitations within pinned queries, you can only pin documents using ids or docs, but cannot use both in single rule.
300
+ It is advised to use one or the other in query rulesets, to avoid errors.
301
+ Additionally, pinned queries have a maximum limit of 100 pinned hits.
302
+ If multiple matching rules pin more than 100 documents, only the first 100 documents are pinned in the order they are specified in the ruleset.</p>
303
+
304
+
305
+ `<https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-query-rules-put-rule>`_
306
+
307
+ :param ruleset_id: The unique identifier of the query ruleset containing the
308
+ rule to be created or updated.
309
+ :param rule_id: The unique identifier of the query rule within the specified
310
+ ruleset to be created or updated.
311
+ :param actions: The actions to take when the rule is matched. The format of this
312
+ action depends on the rule type.
313
+ :param criteria: The criteria that must be met for the rule to be applied. If
314
+ multiple criteria are specified for a rule, all criteria must be met for
315
+ the rule to be applied.
316
+ :param type: The type of rule.
317
+ :param priority:
318
+ """
319
+ if ruleset_id in SKIP_IN_PATH:
320
+ raise ValueError("Empty value passed for parameter 'ruleset_id'")
321
+ if rule_id in SKIP_IN_PATH:
322
+ raise ValueError("Empty value passed for parameter 'rule_id'")
323
+ if actions is None and body is None:
324
+ raise ValueError("Empty value passed for parameter 'actions'")
325
+ if criteria is None and body is None:
326
+ raise ValueError("Empty value passed for parameter 'criteria'")
327
+ if type is None and body is None:
328
+ raise ValueError("Empty value passed for parameter 'type'")
329
+ __path_parts: t.Dict[str, str] = {
330
+ "ruleset_id": _quote(ruleset_id),
331
+ "rule_id": _quote(rule_id),
332
+ }
333
+ __path = f'/_query_rules/{__path_parts["ruleset_id"]}/_rule/{__path_parts["rule_id"]}'
334
+ __query: t.Dict[str, t.Any] = {}
335
+ __body: t.Dict[str, t.Any] = body if body is not None else {}
336
+ if error_trace is not None:
337
+ __query["error_trace"] = error_trace
338
+ if filter_path is not None:
339
+ __query["filter_path"] = filter_path
340
+ if human is not None:
341
+ __query["human"] = human
342
+ if pretty is not None:
343
+ __query["pretty"] = pretty
344
+ if not __body:
345
+ if actions is not None:
346
+ __body["actions"] = actions
347
+ if criteria is not None:
348
+ __body["criteria"] = criteria
349
+ if type is not None:
350
+ __body["type"] = type
351
+ if priority is not None:
352
+ __body["priority"] = priority
353
+ __headers = {"accept": "application/json", "content-type": "application/json"}
354
+ return self.perform_request( # type: ignore[return-value]
355
+ "PUT",
356
+ __path,
357
+ params=__query,
358
+ headers=__headers,
359
+ body=__body,
360
+ endpoint_id="query_rules.put_rule",
361
+ path_parts=__path_parts,
362
+ )
363
+
364
+ @_rewrite_parameters(
365
+ body_fields=("rules",),
366
+ )
367
+ def put_ruleset(
368
+ self,
369
+ *,
370
+ ruleset_id: str,
371
+ rules: t.Optional[
372
+ t.Union[t.Mapping[str, t.Any], t.Sequence[t.Mapping[str, t.Any]]]
373
+ ] = None,
374
+ error_trace: t.Optional[bool] = None,
375
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
376
+ human: t.Optional[bool] = None,
377
+ pretty: t.Optional[bool] = None,
378
+ body: t.Optional[t.Dict[str, t.Any]] = None,
379
+ ) -> ObjectApiResponse[t.Any]:
380
+ """
381
+ .. raw:: html
382
+
383
+ <p>Create or update a query ruleset.
384
+ There is a limit of 100 rules per ruleset.
385
+ This limit can be increased by using the <code>xpack.applications.rules.max_rules_per_ruleset</code> cluster setting.</p>
386
+ <p>IMPORTANT: Due to limitations within pinned queries, you can only select documents using <code>ids</code> or <code>docs</code>, but cannot use both in single rule.
387
+ It is advised to use one or the other in query rulesets, to avoid errors.
388
+ Additionally, pinned queries have a maximum limit of 100 pinned hits.
389
+ If multiple matching rules pin more than 100 documents, only the first 100 documents are pinned in the order they are specified in the ruleset.</p>
390
+
391
+
392
+ `<https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-query-rules-put-ruleset>`_
393
+
394
+ :param ruleset_id: The unique identifier of the query ruleset to be created or
395
+ updated.
396
+ :param rules:
397
+ """
398
+ if ruleset_id in SKIP_IN_PATH:
399
+ raise ValueError("Empty value passed for parameter 'ruleset_id'")
400
+ if rules is None and body is None:
401
+ raise ValueError("Empty value passed for parameter 'rules'")
402
+ __path_parts: t.Dict[str, str] = {"ruleset_id": _quote(ruleset_id)}
403
+ __path = f'/_query_rules/{__path_parts["ruleset_id"]}'
404
+ __query: t.Dict[str, t.Any] = {}
405
+ __body: t.Dict[str, t.Any] = body if body is not None else {}
406
+ if error_trace is not None:
407
+ __query["error_trace"] = error_trace
408
+ if filter_path is not None:
409
+ __query["filter_path"] = filter_path
410
+ if human is not None:
411
+ __query["human"] = human
412
+ if pretty is not None:
413
+ __query["pretty"] = pretty
414
+ if not __body:
415
+ if rules is not None:
416
+ __body["rules"] = rules
417
+ __headers = {"accept": "application/json", "content-type": "application/json"}
418
+ return self.perform_request( # type: ignore[return-value]
419
+ "PUT",
420
+ __path,
421
+ params=__query,
422
+ headers=__headers,
423
+ body=__body,
424
+ endpoint_id="query_rules.put_ruleset",
425
+ path_parts=__path_parts,
426
+ )
427
+
428
+ @_rewrite_parameters(
429
+ body_fields=("match_criteria",),
430
+ )
431
+ def test(
432
+ self,
433
+ *,
434
+ ruleset_id: str,
435
+ match_criteria: t.Optional[t.Mapping[str, t.Any]] = None,
436
+ error_trace: t.Optional[bool] = None,
437
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
438
+ human: t.Optional[bool] = None,
439
+ pretty: t.Optional[bool] = None,
440
+ body: t.Optional[t.Dict[str, t.Any]] = None,
441
+ ) -> ObjectApiResponse[t.Any]:
442
+ """
443
+ .. raw:: html
444
+
445
+ <p>Test a query ruleset.
446
+ Evaluate match criteria against a query ruleset to identify the rules that would match that criteria.</p>
447
+
448
+
449
+ `<https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-query-rules-test>`_
450
+
451
+ :param ruleset_id: The unique identifier of the query ruleset to be created or
452
+ updated
453
+ :param match_criteria: The match criteria to apply to rules in the given query
454
+ ruleset. Match criteria should match the keys defined in the `criteria.metadata`
455
+ field of the rule.
456
+ """
457
+ if ruleset_id in SKIP_IN_PATH:
458
+ raise ValueError("Empty value passed for parameter 'ruleset_id'")
459
+ if match_criteria is None and body is None:
460
+ raise ValueError("Empty value passed for parameter 'match_criteria'")
461
+ __path_parts: t.Dict[str, str] = {"ruleset_id": _quote(ruleset_id)}
462
+ __path = f'/_query_rules/{__path_parts["ruleset_id"]}/_test'
463
+ __query: t.Dict[str, t.Any] = {}
464
+ __body: t.Dict[str, t.Any] = body if body is not None else {}
465
+ if error_trace is not None:
466
+ __query["error_trace"] = error_trace
467
+ if filter_path is not None:
468
+ __query["filter_path"] = filter_path
469
+ if human is not None:
470
+ __query["human"] = human
471
+ if pretty is not None:
472
+ __query["pretty"] = pretty
473
+ if not __body:
474
+ if match_criteria is not None:
475
+ __body["match_criteria"] = match_criteria
476
+ __headers = {"accept": "application/json", "content-type": "application/json"}
477
+ return self.perform_request( # type: ignore[return-value]
478
+ "POST",
479
+ __path,
480
+ params=__query,
481
+ headers=__headers,
482
+ body=__body,
483
+ endpoint_id="query_rules.test",
484
+ path_parts=__path_parts,
485
+ )