Skip to content

Commit 058abd3

Browse files
authored
Merge Query Ruleset API into new Query Rules API (#2607)
1 parent 925e5ed commit 058abd3

File tree

6 files changed

+367
-27
lines changed

6 files changed

+367
-27
lines changed

docs/sphinx/api/query-rules.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ Query rules
55
.. py:module:: elasticsearch.client
66
:noindex:
77

8-
.. autoclass:: QueryRulesetClient
9-
:members:
8+
.. autoclass:: QueryRulesClient
9+
:members:

elasticsearch/_async/client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
from .ml import MlClient
6464
from .monitoring import MonitoringClient
6565
from .nodes import NodesClient
66-
from .query_ruleset import QueryRulesetClient
66+
from .query_rules import QueryRulesClient
6767
from .rollup import RollupClient
6868
from .search_application import SearchApplicationClient
6969
from .searchable_snapshots import SearchableSnapshotsClient
@@ -455,7 +455,7 @@ def __init__(
455455
self.migration = MigrationClient(self)
456456
self.ml = MlClient(self)
457457
self.monitoring = MonitoringClient(self)
458-
self.query_ruleset = QueryRulesetClient(self)
458+
self.query_rules = QueryRulesClient(self)
459459
self.rollup = RollupClient(self)
460460
self.search_application = SearchApplicationClient(self)
461461
self.searchable_snapshots = SearchableSnapshotsClient(self)

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

Lines changed: 180 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,59 @@
2323
from .utils import SKIP_IN_PATH, _quote, _rewrite_parameters
2424

2525

26-
class QueryRulesetClient(NamespacedClient):
26+
class QueryRulesClient(NamespacedClient):
2727

2828
@_rewrite_parameters()
29-
async def delete(
29+
async 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+
Deletes a query rule within a query ruleset.
41+
42+
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/delete-query-rule.html>`_
43+
44+
:param ruleset_id: The unique identifier of the query ruleset containing the
45+
rule to delete
46+
:param rule_id: The unique identifier of the query rule within the specified
47+
ruleset to delete
48+
"""
49+
if ruleset_id in SKIP_IN_PATH:
50+
raise ValueError("Empty value passed for parameter 'ruleset_id'")
51+
if rule_id in SKIP_IN_PATH:
52+
raise ValueError("Empty value passed for parameter 'rule_id'")
53+
__path_parts: t.Dict[str, str] = {
54+
"ruleset_id": _quote(ruleset_id),
55+
"rule_id": _quote(rule_id),
56+
}
57+
__path = f'/_query_rules/{__path_parts["ruleset_id"]}/_rule/{__path_parts["rule_id"]}'
58+
__query: t.Dict[str, t.Any] = {}
59+
if error_trace is not None:
60+
__query["error_trace"] = error_trace
61+
if filter_path is not None:
62+
__query["filter_path"] = filter_path
63+
if human is not None:
64+
__query["human"] = human
65+
if pretty is not None:
66+
__query["pretty"] = pretty
67+
__headers = {"accept": "application/json"}
68+
return await self.perform_request( # type: ignore[return-value]
69+
"DELETE",
70+
__path,
71+
params=__query,
72+
headers=__headers,
73+
endpoint_id="query_rules.delete_rule",
74+
path_parts=__path_parts,
75+
)
76+
77+
@_rewrite_parameters()
78+
async def delete_ruleset(
3079
self,
3180
*,
3281
ruleset_id: str,
@@ -61,12 +110,61 @@ async def delete(
61110
__path,
62111
params=__query,
63112
headers=__headers,
64-
endpoint_id="query_ruleset.delete",
113+
endpoint_id="query_rules.delete_ruleset",
114+
path_parts=__path_parts,
115+
)
116+
117+
@_rewrite_parameters()
118+
async def get_rule(
119+
self,
120+
*,
121+
ruleset_id: str,
122+
rule_id: str,
123+
error_trace: t.Optional[bool] = None,
124+
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
125+
human: t.Optional[bool] = None,
126+
pretty: t.Optional[bool] = None,
127+
) -> ObjectApiResponse[t.Any]:
128+
"""
129+
Returns the details about a query rule within a query ruleset
130+
131+
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/get-query-rule.html>`_
132+
133+
:param ruleset_id: The unique identifier of the query ruleset containing the
134+
rule to retrieve
135+
:param rule_id: The unique identifier of the query rule within the specified
136+
ruleset to retrieve
137+
"""
138+
if ruleset_id in SKIP_IN_PATH:
139+
raise ValueError("Empty value passed for parameter 'ruleset_id'")
140+
if rule_id in SKIP_IN_PATH:
141+
raise ValueError("Empty value passed for parameter 'rule_id'")
142+
__path_parts: t.Dict[str, str] = {
143+
"ruleset_id": _quote(ruleset_id),
144+
"rule_id": _quote(rule_id),
145+
}
146+
__path = f'/_query_rules/{__path_parts["ruleset_id"]}/_rule/{__path_parts["rule_id"]}'
147+
__query: t.Dict[str, t.Any] = {}
148+
if error_trace is not None:
149+
__query["error_trace"] = error_trace
150+
if filter_path is not None:
151+
__query["filter_path"] = filter_path
152+
if human is not None:
153+
__query["human"] = human
154+
if pretty is not None:
155+
__query["pretty"] = pretty
156+
__headers = {"accept": "application/json"}
157+
return await self.perform_request( # type: ignore[return-value]
158+
"GET",
159+
__path,
160+
params=__query,
161+
headers=__headers,
162+
endpoint_id="query_rules.get_rule",
65163
path_parts=__path_parts,
66164
)
67165

68166
@_rewrite_parameters()
69-
async def get(
167+
async def get_ruleset(
70168
self,
71169
*,
72170
ruleset_id: str,
@@ -101,14 +199,14 @@ async def get(
101199
__path,
102200
params=__query,
103201
headers=__headers,
104-
endpoint_id="query_ruleset.get",
202+
endpoint_id="query_rules.get_ruleset",
105203
path_parts=__path_parts,
106204
)
107205

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

154325
@_rewrite_parameters(
155326
body_fields=("rules",),
156327
)
157-
async def put(
328+
async def put_ruleset(
158329
self,
159330
*,
160331
ruleset_id: str,
@@ -200,6 +371,6 @@ async def put(
200371
params=__query,
201372
headers=__headers,
202373
body=__body,
203-
endpoint_id="query_ruleset.put",
374+
endpoint_id="query_rules.put_ruleset",
204375
path_parts=__path_parts,
205376
)

elasticsearch/_sync/client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
from .ml import MlClient
6464
from .monitoring import MonitoringClient
6565
from .nodes import NodesClient
66-
from .query_ruleset import QueryRulesetClient
66+
from .query_rules import QueryRulesClient
6767
from .rollup import RollupClient
6868
from .search_application import SearchApplicationClient
6969
from .searchable_snapshots import SearchableSnapshotsClient
@@ -455,7 +455,7 @@ def __init__(
455455
self.migration = MigrationClient(self)
456456
self.ml = MlClient(self)
457457
self.monitoring = MonitoringClient(self)
458-
self.query_ruleset = QueryRulesetClient(self)
458+
self.query_rules = QueryRulesClient(self)
459459
self.rollup = RollupClient(self)
460460
self.search_application = SearchApplicationClient(self)
461461
self.searchable_snapshots = SearchableSnapshotsClient(self)

0 commit comments

Comments
 (0)