|
| 1 | +[role="xpack"] |
| 2 | +[[test-query-ruleset]] |
| 3 | +=== Test query ruleset |
| 4 | + |
| 5 | +++++ |
| 6 | +<titleabbrev>Tests query ruleset</titleabbrev> |
| 7 | +++++ |
| 8 | + |
| 9 | +Evaluates match criteria against a query ruleset to identify the rules that would match that criteria. |
| 10 | + |
| 11 | +preview::[] |
| 12 | + |
| 13 | +[[test-query-ruleset-request]] |
| 14 | +==== {api-request-title} |
| 15 | + |
| 16 | +`POST _query_rules/<ruleset_id>/_test` |
| 17 | + |
| 18 | +[[test-query-ruleset-prereq]] |
| 19 | +==== {api-prereq-title} |
| 20 | + |
| 21 | +Requires the `manage_search_query_rules` privilege. |
| 22 | + |
| 23 | +[[test-query-ruleset-path-params]] |
| 24 | +==== {api-path-parms-title} |
| 25 | + |
| 26 | +`<ruleset_id>`:: |
| 27 | +(Required, string) |
| 28 | + |
| 29 | +[[test-query-rule-request-body]] |
| 30 | +==== {api-request-body-title} |
| 31 | + |
| 32 | +`match_criteria`:: |
| 33 | +(Required, object) Defines the match criteria to apply to rules in the given query ruleset. |
| 34 | +Match criteria should match the keys defined in the `criteria.metadata` field of the rule. |
| 35 | + |
| 36 | +[[test-query-ruleset-response-codes]] |
| 37 | +==== {api-response-codes-title} |
| 38 | + |
| 39 | +`400`:: |
| 40 | +The `ruleset_id` or `match_criteria` were not provided. |
| 41 | + |
| 42 | +`404` (Missing resources):: |
| 43 | +No query ruleset matching `ruleset_id` could be found. |
| 44 | + |
| 45 | +[[test-query-ruleset-example]] |
| 46 | +==== {api-examples-title} |
| 47 | + |
| 48 | +To test a ruleset, provide the match criteria that you want to test against: |
| 49 | + |
| 50 | +//// |
| 51 | +
|
| 52 | +[source,console] |
| 53 | +-------------------------------------------------- |
| 54 | +PUT _query_rules/my-ruleset |
| 55 | +{ |
| 56 | + "rules": [ |
| 57 | + { |
| 58 | + "rule_id": "my-rule1", |
| 59 | + "type": "pinned", |
| 60 | + "criteria": [ |
| 61 | + { |
| 62 | + "type": "contains", |
| 63 | + "metadata": "query_string", |
| 64 | + "values": [ "pugs", "puggles" ] |
| 65 | + } |
| 66 | + ], |
| 67 | + "actions": { |
| 68 | + "ids": [ |
| 69 | + "id1", |
| 70 | + "id2" |
| 71 | + ] |
| 72 | + } |
| 73 | + }, |
| 74 | + { |
| 75 | + "rule_id": "my-rule2", |
| 76 | + "type": "pinned", |
| 77 | + "criteria": [ |
| 78 | + { |
| 79 | + "type": "fuzzy", |
| 80 | + "metadata": "query_string", |
| 81 | + "values": [ "rescue dogs" ] |
| 82 | + } |
| 83 | + ], |
| 84 | + "actions": { |
| 85 | + "docs": [ |
| 86 | + { |
| 87 | + "_index": "index1", |
| 88 | + "_id": "id3" |
| 89 | + }, |
| 90 | + { |
| 91 | + "_index": "index2", |
| 92 | + "_id": "id4" |
| 93 | + } |
| 94 | + ] |
| 95 | + } |
| 96 | + } |
| 97 | + ] |
| 98 | +} |
| 99 | +-------------------------------------------------- |
| 100 | +// TESTSETUP |
| 101 | +
|
| 102 | +[source,console] |
| 103 | +-------------------------------------------------- |
| 104 | +DELETE _query_rules/my-ruleset |
| 105 | +-------------------------------------------------- |
| 106 | +// TEARDOWN |
| 107 | +
|
| 108 | +//// |
| 109 | + |
| 110 | +[source,console] |
| 111 | +---- |
| 112 | +POST _query_rules/my-ruleset/_test |
| 113 | +{ |
| 114 | + "match_criteria": { |
| 115 | + "query_string": "puggles" |
| 116 | + } |
| 117 | +} |
| 118 | +---- |
| 119 | + |
| 120 | +A sample response: |
| 121 | + |
| 122 | +[source,console-result] |
| 123 | +---- |
| 124 | +{ |
| 125 | + "total_matched_rules": 1, |
| 126 | + "matched_rules": [ |
| 127 | + { |
| 128 | + "ruleset_id": "my-ruleset", |
| 129 | + "rule_id": "my-rule1" |
| 130 | + } |
| 131 | + ] |
| 132 | +} |
| 133 | +---- |
0 commit comments