diff --git a/docs/sphinx/api/query-rules.rst b/docs/sphinx/api/query-rules.rst index fd42e9b2d..adcfda99e 100644 --- a/docs/sphinx/api/query-rules.rst +++ b/docs/sphinx/api/query-rules.rst @@ -5,5 +5,5 @@ Query rules .. py:module:: elasticsearch.client :noindex: -.. autoclass:: QueryRulesetClient - :members: \ No newline at end of file +.. autoclass:: QueryRulesClient + :members: diff --git a/elasticsearch/_async/client/__init__.py b/elasticsearch/_async/client/__init__.py index 440e211e1..5b2979f15 100644 --- a/elasticsearch/_async/client/__init__.py +++ b/elasticsearch/_async/client/__init__.py @@ -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 @@ -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) diff --git a/elasticsearch/_async/client/query_ruleset.py b/elasticsearch/_async/client/query_rules.py similarity index 50% rename from elasticsearch/_async/client/query_ruleset.py rename to elasticsearch/_async/client/query_rules.py index 685a4ff36..4a64f8b2d 100644 --- a/elasticsearch/_async/client/query_ruleset.py +++ b/elasticsearch/_async/client/query_rules.py @@ -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. + + ``_ + + :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, @@ -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 + + ``_ + + :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, @@ -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, @@ -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. + + ``_ + + :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, @@ -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, ) diff --git a/elasticsearch/_sync/client/__init__.py b/elasticsearch/_sync/client/__init__.py index cc4112ec9..180f4bc65 100644 --- a/elasticsearch/_sync/client/__init__.py +++ b/elasticsearch/_sync/client/__init__.py @@ -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 @@ -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) diff --git a/elasticsearch/_sync/client/query_ruleset.py b/elasticsearch/_sync/client/query_rules.py similarity index 50% rename from elasticsearch/_sync/client/query_ruleset.py rename to elasticsearch/_sync/client/query_rules.py index f4f7b59fc..d0ba355c8 100644 --- a/elasticsearch/_sync/client/query_ruleset.py +++ b/elasticsearch/_sync/client/query_rules.py @@ -23,10 +23,59 @@ from .utils import SKIP_IN_PATH, _quote, _rewrite_parameters -class QueryRulesetClient(NamespacedClient): +class QueryRulesClient(NamespacedClient): @_rewrite_parameters() - def delete( + 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. + + ``_ + + :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 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() + def delete_ruleset( self, *, ruleset_id: str, @@ -61,12 +110,61 @@ def delete( __path, params=__query, headers=__headers, - endpoint_id="query_ruleset.delete", + endpoint_id="query_rules.delete_ruleset", + path_parts=__path_parts, + ) + + @_rewrite_parameters() + 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 + + ``_ + + :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 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() - def get( + def get_ruleset( self, *, ruleset_id: str, @@ -101,14 +199,14 @@ 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_"}, ) - def list( + def list_rulesets( self, *, error_trace: t.Optional[bool] = None, @@ -147,14 +245,87 @@ 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"), + ) + 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. + + ``_ + + :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 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",), ) - def put( + def put_ruleset( self, *, ruleset_id: str, @@ -200,6 +371,6 @@ def put( params=__query, headers=__headers, body=__body, - endpoint_id="query_ruleset.put", + endpoint_id="query_rules.put_ruleset", path_parts=__path_parts, ) diff --git a/elasticsearch/client.py b/elasticsearch/client.py index 8c028e3fc..91079df36 100644 --- a/elasticsearch/client.py +++ b/elasticsearch/client.py @@ -46,9 +46,7 @@ from ._sync.client.ml import MlClient as MlClient # noqa: F401 from ._sync.client.monitoring import MonitoringClient as MonitoringClient # noqa: F401 from ._sync.client.nodes import NodesClient as NodesClient # noqa: F401 -from ._sync.client.query_ruleset import ( # noqa: F401 - QueryRulesetClient as QueryRulesetClient, -) +from ._sync.client.query_rules import QueryRulesClient as QueryRulesClient # noqa: F401 from ._sync.client.rollup import RollupClient as RollupClient # noqa: F401 from ._sync.client.search_application import ( # noqa: F401 SearchApplicationClient as SearchApplicationClient,