# Query rules

class elasticsearch.client.QueryRulesClient

  To use this client, access `client.query_rules` from an `Elasticsearch` client. For example:

      from elasticsearch import Elasticsearch

      # Create the client instance
      client = Elasticsearch(...)
      # Use the query_rules client
      client.query_rules.<method>(...)

  delete_rule(*, ruleset_id, rule_id, error_trace=None, filter_path=None, human=None, pretty=None)

    Delete a query rule.

    Delete a query rule within a query ruleset. This is a destructive action that is only recoverable by re-adding the same rule with the create or update query rule API.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-query-rules-delete-rule

    Parameters:

      - ruleset_id (str) – The unique identifier of the query ruleset containing the rule to delete

      - rule_id (str) – The unique identifier of the query rule within the specified ruleset to delete

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

    Return type:

      ObjectApiResponse[Any]

  delete_ruleset(*, ruleset_id, error_trace=None, filter_path=None, human=None, pretty=None)

    Delete a query ruleset.

    Remove a query ruleset and its associated data. This is a destructive action that is not recoverable.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-query-rules-delete-ruleset

    Parameters:

      - ruleset_id (str) – The unique identifier of the query ruleset to delete

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

    Return type:

      ObjectApiResponse[Any]

  get_rule(*, ruleset_id, rule_id, error_trace=None, filter_path=None, human=None, pretty=None)

    Get a query rule.

    Get details about a query rule within a query ruleset.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-query-rules-get-rule

    Parameters:

      - ruleset_id (str) – The unique identifier of the query ruleset containing the rule to retrieve

      - rule_id (str) – The unique identifier of the query rule within the specified ruleset to retrieve

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

    Return type:

      ObjectApiResponse[Any]

  get_ruleset(*, ruleset_id, error_trace=None, filter_path=None, human=None, pretty=None)

    Get a query ruleset.

    Get details about a query ruleset.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-query-rules-get-ruleset

    Parameters:

      - ruleset_id (str) – The unique identifier of the query ruleset

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

    Return type:

      ObjectApiResponse[Any]

  list_rulesets(*, error_trace=None, filter_path=None, from_=None, human=None, pretty=None, size=None)

    Get all query rulesets.

    Get summarized information about the query rulesets.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-query-rules-list-rulesets

    Parameters:

      - from – The offset from the first result to fetch.

      - size (int | None) – The maximum number of results to retrieve.

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - from_ (int | None)

      - human (bool | None)

      - pretty (bool | None)

    Return type:

      ObjectApiResponse[Any]

  put_rule(*, ruleset_id, rule_id, actions=None, criteria=None, type=None, error_trace=None, filter_path=None, human=None, pretty=None, priority=None, body=None)

    Create or update a query rule.

    Create or update a query rule within a query ruleset.

    IMPORTANT: Due to limitations within pinned queries, you can only pin documents using ids or docs, but cannot use both in single rule. It is advised to use one or the other in query rulesets, to avoid errors. Additionally, pinned queries have a maximum limit of 100 pinned hits. 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.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-query-rules-put-rule

    Parameters:

      - ruleset_id (str) – The unique identifier of the query ruleset containing the rule to be created or updated.

      - rule_id (str) – The unique identifier of the query rule within the specified ruleset to be created or updated.

      - actions (Mapping[str, Any] | None) – The actions to take when the rule is matched. The format of this action depends on the rule type.

      - criteria (Mapping[str, Any] | Sequence[Mapping[str, Any]] | None) – The criteria that must be met for the rule to be applied. If multiple criteria are specified for a rule, all criteria must be met for the rule to be applied.

      - type (str | Literal['exclude', 'pinned'] | None) – The type of rule.

      - priority (int | None)

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

      - body (Dict[str, Any] | None)

    Return type:

      ObjectApiResponse[Any]

  put_ruleset(*, ruleset_id, rules=None, error_trace=None, filter_path=None, human=None, pretty=None, body=None)

    Create or update a query ruleset.

    There is a limit of 100 rules per ruleset. This limit can be increased by using the `xpack.applications.rules.max_rules_per_ruleset` cluster setting.

    IMPORTANT: Due to limitations within pinned queries, you can only select documents using `ids` or `docs`, but cannot use both in single rule. It is advised to use one or the other in query rulesets, to avoid errors. Additionally, pinned queries have a maximum limit of 100 pinned hits. 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.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-query-rules-put-ruleset

    Parameters:

      - ruleset_id (str) – The unique identifier of the query ruleset to be created or updated.

      - rules (Mapping[str, Any] | Sequence[Mapping[str, Any]] | None)

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

      - body (Dict[str, Any] | None)

    Return type:

      ObjectApiResponse[Any]

  test(*, ruleset_id, match_criteria=None, error_trace=None, filter_path=None, human=None, pretty=None, body=None)

    Test a query ruleset.

    Evaluate match criteria against a query ruleset to identify the rules that would match that criteria.

    https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation-query-rules-test

    Parameters:

      - ruleset_id (str) – The unique identifier of the query ruleset to be created or updated

      - match_criteria (Mapping[str, Any] | None) – The match criteria to apply to rules in the given query ruleset. Match criteria should match the keys defined in the criteria.metadata field of the rule.

      - error_trace (bool | None)

      - filter_path (str | Sequence[str] | None)

      - human (bool | None)

      - pretty (bool | None)

      - body (Dict[str, Any] | None)

    Return type:

      ObjectApiResponse[Any]