Test query ruleset

Test query ruleset

New API reference

For the most up-to-date API details, refer to Query rules APIs.

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

This functionality is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.

Request

POST _query_rules/<ruleset_id>/_test

Prerequisites

Requires the manage_search_query_rules privilege.

Path parameters

<ruleset_id>

(Required, string)

Request body

match_criteria

(Required, object) Defines 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.

Response codes

400

The ruleset_id or match_criteria were not provided.

404 (Missing resources)

No query ruleset matching ruleset_id could be found.

Examples

To test a ruleset, provide the match criteria that you want to test against:

  1. resp = client.query_rules.test(
  2. ruleset_id="my-ruleset",
  3. match_criteria={
  4. "query_string": "puggles"
  5. },
  6. )
  7. print(resp)
  1. const response = await client.transport.request({
  2. method: "POST",
  3. path: "/_query_rules/my-ruleset/_test",
  4. body: {
  5. match_criteria: {
  6. query_string: "puggles",
  7. },
  8. },
  9. });
  10. console.log(response);
  1. POST _query_rules/my-ruleset/_test
  2. {
  3. "match_criteria": {
  4. "query_string": "puggles"
  5. }
  6. }

A sample response:

  1. {
  2. "total_matched_rules": 1,
  3. "matched_rules": [
  4. {
  5. "ruleset_id": "my-ruleset",
  6. "rule_id": "my-rule1"
  7. }
  8. ]
  9. }