Skip to content

Merge Query Ruleset API into new Query Rules API #2607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/sphinx/api/query-rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ Query rules
.. py:module:: elasticsearch.client
:noindex:

.. autoclass:: QueryRulesetClient
:members:
.. autoclass:: QueryRulesClient
:members:
4 changes: 2 additions & 2 deletions elasticsearch/_async/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
from .ml import MlClient
from .monitoring import MonitoringClient
from .nodes import NodesClient
from .query_ruleset import QueryRulesetClient
from .query_rules import QueryRulesClient
from .rollup import RollupClient
from .search_application import SearchApplicationClient
from .searchable_snapshots import SearchableSnapshotsClient
Expand Down Expand Up @@ -455,7 +455,7 @@ def __init__(
self.migration = MigrationClient(self)
self.ml = MlClient(self)
self.monitoring = MonitoringClient(self)
self.query_ruleset = QueryRulesetClient(self)
self.query_rules = QueryRulesClient(self)
self.rollup = RollupClient(self)
self.search_application = SearchApplicationClient(self)
self.searchable_snapshots = SearchableSnapshotsClient(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,59 @@
from .utils import SKIP_IN_PATH, _quote, _rewrite_parameters


class QueryRulesetClient(NamespacedClient):
class QueryRulesClient(NamespacedClient):

@_rewrite_parameters()
async def delete(
async def delete_rule(
self,
*,
ruleset_id: str,
rule_id: str,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
Deletes a query rule within a query ruleset.

`<https://www.elastic.co/guide/en/elasticsearch/reference/master/delete-query-rule.html>`_

:param ruleset_id: The unique identifier of the query ruleset containing the
rule to delete
:param rule_id: The unique identifier of the query rule within the specified
ruleset to delete
"""
if ruleset_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'ruleset_id'")
if rule_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'rule_id'")
__path_parts: t.Dict[str, str] = {
"ruleset_id": _quote(ruleset_id),
"rule_id": _quote(rule_id),
}
__path = f'/_query_rules/{__path_parts["ruleset_id"]}/_rule/{__path_parts["rule_id"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="query_rules.delete_rule",
path_parts=__path_parts,
)

@_rewrite_parameters()
async def delete_ruleset(
self,
*,
ruleset_id: str,
Expand Down Expand Up @@ -61,12 +110,61 @@ async def delete(
__path,
params=__query,
headers=__headers,
endpoint_id="query_ruleset.delete",
endpoint_id="query_rules.delete_ruleset",
path_parts=__path_parts,
)

@_rewrite_parameters()
async def get_rule(
self,
*,
ruleset_id: str,
rule_id: str,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
Returns the details about a query rule within a query ruleset

`<https://www.elastic.co/guide/en/elasticsearch/reference/master/get-query-rule.html>`_

:param ruleset_id: The unique identifier of the query ruleset containing the
rule to retrieve
:param rule_id: The unique identifier of the query rule within the specified
ruleset to retrieve
"""
if ruleset_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'ruleset_id'")
if rule_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'rule_id'")
__path_parts: t.Dict[str, str] = {
"ruleset_id": _quote(ruleset_id),
"rule_id": _quote(rule_id),
}
__path = f'/_query_rules/{__path_parts["ruleset_id"]}/_rule/{__path_parts["rule_id"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="query_rules.get_rule",
path_parts=__path_parts,
)

@_rewrite_parameters()
async def get(
async def get_ruleset(
self,
*,
ruleset_id: str,
Expand Down Expand Up @@ -101,14 +199,14 @@ async def get(
__path,
params=__query,
headers=__headers,
endpoint_id="query_ruleset.get",
endpoint_id="query_rules.get_ruleset",
path_parts=__path_parts,
)

@_rewrite_parameters(
parameter_aliases={"from": "from_"},
)
async def list(
async def list_rulesets(
self,
*,
error_trace: t.Optional[bool] = None,
Expand Down Expand Up @@ -147,14 +245,87 @@ async def list(
__path,
params=__query,
headers=__headers,
endpoint_id="query_ruleset.list",
endpoint_id="query_rules.list_rulesets",
path_parts=__path_parts,
)

@_rewrite_parameters(
body_fields=("actions", "criteria", "type"),
)
async def put_rule(
self,
*,
ruleset_id: str,
rule_id: str,
actions: t.Optional[t.Mapping[str, t.Any]] = None,
criteria: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
type: t.Optional[t.Union["t.Literal['pinned']", str]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
Creates or updates a query rule within a query ruleset.

`<https://www.elastic.co/guide/en/elasticsearch/reference/master/put-query-rule.html>`_

:param ruleset_id: The unique identifier of the query ruleset containing the
rule to be created or updated
:param rule_id: The unique identifier of the query rule within the specified
ruleset to be created or updated
:param actions:
:param criteria:
:param type:
"""
if ruleset_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'ruleset_id'")
if rule_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'rule_id'")
if actions is None and body is None:
raise ValueError("Empty value passed for parameter 'actions'")
if criteria is None and body is None:
raise ValueError("Empty value passed for parameter 'criteria'")
if type is None and body is None:
raise ValueError("Empty value passed for parameter 'type'")
__path_parts: t.Dict[str, str] = {
"ruleset_id": _quote(ruleset_id),
"rule_id": _quote(rule_id),
}
__path = f'/_query_rules/{__path_parts["ruleset_id"]}/_rule/{__path_parts["rule_id"]}'
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if actions is not None:
__body["actions"] = actions
if criteria is not None:
__body["criteria"] = criteria
if type is not None:
__body["type"] = type
__headers = {"accept": "application/json", "content-type": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="query_rules.put_rule",
path_parts=__path_parts,
)

@_rewrite_parameters(
body_fields=("rules",),
)
async def put(
async def put_ruleset(
self,
*,
ruleset_id: str,
Expand Down Expand Up @@ -200,6 +371,6 @@ async def put(
params=__query,
headers=__headers,
body=__body,
endpoint_id="query_ruleset.put",
endpoint_id="query_rules.put_ruleset",
path_parts=__path_parts,
)
4 changes: 2 additions & 2 deletions elasticsearch/_sync/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
from .ml import MlClient
from .monitoring import MonitoringClient
from .nodes import NodesClient
from .query_ruleset import QueryRulesetClient
from .query_rules import QueryRulesClient
from .rollup import RollupClient
from .search_application import SearchApplicationClient
from .searchable_snapshots import SearchableSnapshotsClient
Expand Down Expand Up @@ -455,7 +455,7 @@ def __init__(
self.migration = MigrationClient(self)
self.ml = MlClient(self)
self.monitoring = MonitoringClient(self)
self.query_ruleset = QueryRulesetClient(self)
self.query_rules = QueryRulesClient(self)
self.rollup = RollupClient(self)
self.search_application = SearchApplicationClient(self)
self.searchable_snapshots = SearchableSnapshotsClient(self)
Expand Down
Loading
Loading