Skip to content

Commit f3fc4fe

Browse files
authored
Add Query Rules API (#71)
1 parent b44f72e commit f3fc4fe

File tree

5 files changed

+367
-25
lines changed

5 files changed

+367
-25
lines changed

elasticsearch_serverless/_async/client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from .license import LicenseClient
4848
from .logstash import LogstashClient
4949
from .ml import MlClient
50-
from .query_ruleset import QueryRulesetClient
50+
from .query_rules import QueryRulesClient
5151
from .search_application import SearchApplicationClient
5252
from .security import SecurityClient
5353
from .sql import SqlClient
@@ -292,7 +292,7 @@ def __init__(
292292
self.license = LicenseClient(self)
293293
self.logstash = LogstashClient(self)
294294
self.ml = MlClient(self)
295-
self.query_ruleset = QueryRulesetClient(self)
295+
self.query_rules = QueryRulesClient(self)
296296
self.search_application = SearchApplicationClient(self)
297297
self.security = SecurityClient(self)
298298
self.sql = SqlClient(self)

elasticsearch_serverless/_async/client/query_ruleset.py renamed to elasticsearch_serverless/_async/client/query_rules.py

Lines changed: 181 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
1819
import typing as t
1920

2021
from elastic_transport import ObjectApiResponse
@@ -23,10 +24,59 @@
2324
from .utils import SKIP_IN_PATH, _quote, _rewrite_parameters
2425

2526

26-
class QueryRulesetClient(NamespacedClient):
27+
class QueryRulesClient(NamespacedClient):
2728

2829
@_rewrite_parameters()
29-
async def delete(
30+
async def delete_rule(
31+
self,
32+
*,
33+
ruleset_id: str,
34+
rule_id: str,
35+
error_trace: t.Optional[bool] = None,
36+
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
37+
human: t.Optional[bool] = None,
38+
pretty: t.Optional[bool] = None,
39+
) -> ObjectApiResponse[t.Any]:
40+
"""
41+
Deletes a query rule within a query ruleset.
42+
43+
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/delete-query-rule.html>`_
44+
45+
:param ruleset_id: The unique identifier of the query ruleset containing the
46+
rule to delete
47+
:param rule_id: The unique identifier of the query rule within the specified
48+
ruleset to delete
49+
"""
50+
if ruleset_id in SKIP_IN_PATH:
51+
raise ValueError("Empty value passed for parameter 'ruleset_id'")
52+
if rule_id in SKIP_IN_PATH:
53+
raise ValueError("Empty value passed for parameter 'rule_id'")
54+
__path_parts: t.Dict[str, str] = {
55+
"ruleset_id": _quote(ruleset_id),
56+
"rule_id": _quote(rule_id),
57+
}
58+
__path = f'/_query_rules/{__path_parts["ruleset_id"]}/_rule/{__path_parts["rule_id"]}'
59+
__query: t.Dict[str, t.Any] = {}
60+
if error_trace is not None:
61+
__query["error_trace"] = error_trace
62+
if filter_path is not None:
63+
__query["filter_path"] = filter_path
64+
if human is not None:
65+
__query["human"] = human
66+
if pretty is not None:
67+
__query["pretty"] = pretty
68+
__headers = {"accept": "application/json"}
69+
return await self.perform_request( # type: ignore[return-value]
70+
"DELETE",
71+
__path,
72+
params=__query,
73+
headers=__headers,
74+
endpoint_id="query_rules.delete_rule",
75+
path_parts=__path_parts,
76+
)
77+
78+
@_rewrite_parameters()
79+
async def delete_ruleset(
3080
self,
3181
*,
3282
ruleset_id: str,
@@ -61,12 +111,61 @@ async def delete(
61111
__path,
62112
params=__query,
63113
headers=__headers,
64-
endpoint_id="query_ruleset.delete",
114+
endpoint_id="query_rules.delete_ruleset",
65115
path_parts=__path_parts,
66116
)
67117

68118
@_rewrite_parameters()
69-
async def get(
119+
async def get_rule(
120+
self,
121+
*,
122+
ruleset_id: str,
123+
rule_id: str,
124+
error_trace: t.Optional[bool] = None,
125+
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
126+
human: t.Optional[bool] = None,
127+
pretty: t.Optional[bool] = None,
128+
) -> ObjectApiResponse[t.Any]:
129+
"""
130+
Returns the details about a query rule within a query ruleset
131+
132+
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/get-query-rule.html>`_
133+
134+
:param ruleset_id: The unique identifier of the query ruleset containing the
135+
rule to retrieve
136+
:param rule_id: The unique identifier of the query rule within the specified
137+
ruleset to retrieve
138+
"""
139+
if ruleset_id in SKIP_IN_PATH:
140+
raise ValueError("Empty value passed for parameter 'ruleset_id'")
141+
if rule_id in SKIP_IN_PATH:
142+
raise ValueError("Empty value passed for parameter 'rule_id'")
143+
__path_parts: t.Dict[str, str] = {
144+
"ruleset_id": _quote(ruleset_id),
145+
"rule_id": _quote(rule_id),
146+
}
147+
__path = f'/_query_rules/{__path_parts["ruleset_id"]}/_rule/{__path_parts["rule_id"]}'
148+
__query: t.Dict[str, t.Any] = {}
149+
if error_trace is not None:
150+
__query["error_trace"] = error_trace
151+
if filter_path is not None:
152+
__query["filter_path"] = filter_path
153+
if human is not None:
154+
__query["human"] = human
155+
if pretty is not None:
156+
__query["pretty"] = pretty
157+
__headers = {"accept": "application/json"}
158+
return await self.perform_request( # type: ignore[return-value]
159+
"GET",
160+
__path,
161+
params=__query,
162+
headers=__headers,
163+
endpoint_id="query_rules.get_rule",
164+
path_parts=__path_parts,
165+
)
166+
167+
@_rewrite_parameters()
168+
async def get_ruleset(
70169
self,
71170
*,
72171
ruleset_id: str,
@@ -101,14 +200,14 @@ async def get(
101200
__path,
102201
params=__query,
103202
headers=__headers,
104-
endpoint_id="query_ruleset.get",
203+
endpoint_id="query_rules.get_ruleset",
105204
path_parts=__path_parts,
106205
)
107206

108207
@_rewrite_parameters(
109208
parameter_aliases={"from": "from_"},
110209
)
111-
async def list(
210+
async def list_rulesets(
112211
self,
113212
*,
114213
error_trace: t.Optional[bool] = None,
@@ -147,14 +246,87 @@ async def list(
147246
__path,
148247
params=__query,
149248
headers=__headers,
150-
endpoint_id="query_ruleset.list",
249+
endpoint_id="query_rules.list_rulesets",
250+
path_parts=__path_parts,
251+
)
252+
253+
@_rewrite_parameters(
254+
body_fields=("actions", "criteria", "type"),
255+
)
256+
async def put_rule(
257+
self,
258+
*,
259+
ruleset_id: str,
260+
rule_id: str,
261+
actions: t.Optional[t.Mapping[str, t.Any]] = None,
262+
criteria: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
263+
type: t.Optional[t.Union["t.Literal['pinned']", str]] = None,
264+
error_trace: t.Optional[bool] = None,
265+
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
266+
human: t.Optional[bool] = None,
267+
pretty: t.Optional[bool] = None,
268+
body: t.Optional[t.Dict[str, t.Any]] = None,
269+
) -> ObjectApiResponse[t.Any]:
270+
"""
271+
Creates or updates a query rule within a query ruleset.
272+
273+
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/put-query-rule.html>`_
274+
275+
:param ruleset_id: The unique identifier of the query ruleset containing the
276+
rule to be created or updated
277+
:param rule_id: The unique identifier of the query rule within the specified
278+
ruleset to be created or updated
279+
:param actions:
280+
:param criteria:
281+
:param type:
282+
"""
283+
if ruleset_id in SKIP_IN_PATH:
284+
raise ValueError("Empty value passed for parameter 'ruleset_id'")
285+
if rule_id in SKIP_IN_PATH:
286+
raise ValueError("Empty value passed for parameter 'rule_id'")
287+
if actions is None and body is None:
288+
raise ValueError("Empty value passed for parameter 'actions'")
289+
if criteria is None and body is None:
290+
raise ValueError("Empty value passed for parameter 'criteria'")
291+
if type is None and body is None:
292+
raise ValueError("Empty value passed for parameter 'type'")
293+
__path_parts: t.Dict[str, str] = {
294+
"ruleset_id": _quote(ruleset_id),
295+
"rule_id": _quote(rule_id),
296+
}
297+
__path = f'/_query_rules/{__path_parts["ruleset_id"]}/_rule/{__path_parts["rule_id"]}'
298+
__query: t.Dict[str, t.Any] = {}
299+
__body: t.Dict[str, t.Any] = body if body is not None else {}
300+
if error_trace is not None:
301+
__query["error_trace"] = error_trace
302+
if filter_path is not None:
303+
__query["filter_path"] = filter_path
304+
if human is not None:
305+
__query["human"] = human
306+
if pretty is not None:
307+
__query["pretty"] = pretty
308+
if not __body:
309+
if actions is not None:
310+
__body["actions"] = actions
311+
if criteria is not None:
312+
__body["criteria"] = criteria
313+
if type is not None:
314+
__body["type"] = type
315+
__headers = {"accept": "application/json", "content-type": "application/json"}
316+
return await self.perform_request( # type: ignore[return-value]
317+
"PUT",
318+
__path,
319+
params=__query,
320+
headers=__headers,
321+
body=__body,
322+
endpoint_id="query_rules.put_rule",
151323
path_parts=__path_parts,
152324
)
153325

154326
@_rewrite_parameters(
155327
body_fields=("rules",),
156328
)
157-
async def put(
329+
async def put_ruleset(
158330
self,
159331
*,
160332
ruleset_id: str,
@@ -200,6 +372,6 @@ async def put(
200372
params=__query,
201373
headers=__headers,
202374
body=__body,
203-
endpoint_id="query_ruleset.put",
375+
endpoint_id="query_rules.put_ruleset",
204376
path_parts=__path_parts,
205377
)

elasticsearch_serverless/_sync/client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from .license import LicenseClient
4848
from .logstash import LogstashClient
4949
from .ml import MlClient
50-
from .query_ruleset import QueryRulesetClient
50+
from .query_rules import QueryRulesClient
5151
from .search_application import SearchApplicationClient
5252
from .security import SecurityClient
5353
from .sql import SqlClient
@@ -292,7 +292,7 @@ def __init__(
292292
self.license = LicenseClient(self)
293293
self.logstash = LogstashClient(self)
294294
self.ml = MlClient(self)
295-
self.query_ruleset = QueryRulesetClient(self)
295+
self.query_rules = QueryRulesClient(self)
296296
self.search_application = SearchApplicationClient(self)
297297
self.security = SecurityClient(self)
298298
self.sql = SqlClient(self)

0 commit comments

Comments
 (0)