forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a query rules tester API call (elastic#114168)
* Add a query rules tester API call * Update docs/changelog/114168.yaml * Wrap client call in async with origin * Remove unused param * PR feedback * Remove redundant test * CI workaround - add ent-search as ml dependency so it can find node features
- Loading branch information
Showing
19 changed files
with
951 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 114168 | ||
summary: Add a query rules tester API call | ||
area: Relevance | ||
type: enhancement | ||
issues: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
docs/reference/query-rules/apis/test-query-ruleset.asciidoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
[role="xpack"] | ||
[[test-query-ruleset]] | ||
=== Test query ruleset | ||
|
||
++++ | ||
<titleabbrev>Tests query ruleset</titleabbrev> | ||
++++ | ||
|
||
Evaluates match criteria against a query ruleset to identify the rules that would match that criteria. | ||
|
||
preview::[] | ||
|
||
[[test-query-ruleset-request]] | ||
==== {api-request-title} | ||
|
||
`POST _query_rules/<ruleset_id>/_test` | ||
|
||
[[test-query-ruleset-prereq]] | ||
==== {api-prereq-title} | ||
|
||
Requires the `manage_search_query_rules` privilege. | ||
|
||
[[test-query-ruleset-path-params]] | ||
==== {api-path-parms-title} | ||
|
||
`<ruleset_id>`:: | ||
(Required, string) | ||
|
||
[[test-query-rule-request-body]] | ||
==== {api-request-body-title} | ||
|
||
`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. | ||
|
||
[[test-query-ruleset-response-codes]] | ||
==== {api-response-codes-title} | ||
|
||
`400`:: | ||
The `ruleset_id` or `match_criteria` were not provided. | ||
|
||
`404` (Missing resources):: | ||
No query ruleset matching `ruleset_id` could be found. | ||
|
||
[[test-query-ruleset-example]] | ||
==== {api-examples-title} | ||
|
||
To test a ruleset, provide the match criteria that you want to test against: | ||
|
||
//// | ||
[source,console] | ||
-------------------------------------------------- | ||
PUT _query_rules/my-ruleset | ||
{ | ||
"rules": [ | ||
{ | ||
"rule_id": "my-rule1", | ||
"type": "pinned", | ||
"criteria": [ | ||
{ | ||
"type": "contains", | ||
"metadata": "query_string", | ||
"values": [ "pugs", "puggles" ] | ||
} | ||
], | ||
"actions": { | ||
"ids": [ | ||
"id1", | ||
"id2" | ||
] | ||
} | ||
}, | ||
{ | ||
"rule_id": "my-rule2", | ||
"type": "pinned", | ||
"criteria": [ | ||
{ | ||
"type": "fuzzy", | ||
"metadata": "query_string", | ||
"values": [ "rescue dogs" ] | ||
} | ||
], | ||
"actions": { | ||
"docs": [ | ||
{ | ||
"_index": "index1", | ||
"_id": "id3" | ||
}, | ||
{ | ||
"_index": "index2", | ||
"_id": "id4" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
-------------------------------------------------- | ||
// TESTSETUP | ||
[source,console] | ||
-------------------------------------------------- | ||
DELETE _query_rules/my-ruleset | ||
-------------------------------------------------- | ||
// TEARDOWN | ||
//// | ||
|
||
[source,console] | ||
---- | ||
POST _query_rules/my-ruleset/_test | ||
{ | ||
"match_criteria": { | ||
"query_string": "puggles" | ||
} | ||
} | ||
---- | ||
|
||
A sample response: | ||
|
||
[source,console-result] | ||
---- | ||
{ | ||
"total_matched_rules": 1, | ||
"matched_rules": [ | ||
{ | ||
"ruleset_id": "my-ruleset", | ||
"rule_id": "my-rule1" | ||
} | ||
] | ||
} | ||
---- |
38 changes: 38 additions & 0 deletions
38
rest-api-spec/src/main/resources/rest-api-spec/api/query_rules.test.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"query_rules.test": { | ||
"documentation": { | ||
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/test-query-ruleset.html", | ||
"description": "Tests a query ruleset to identify the rules that would match input criteria" | ||
}, | ||
"stability": "experimental", | ||
"visibility": "public", | ||
"headers": { | ||
"accept": [ | ||
"application/json" | ||
], | ||
"content_type": [ | ||
"application/json" | ||
] | ||
}, | ||
"url": { | ||
"paths": [ | ||
{ | ||
"path": "/_query_rules/{ruleset_id}/_test", | ||
"methods": [ | ||
"POST" | ||
], | ||
"parts": { | ||
"ruleset_id": { | ||
"type": "string", | ||
"description": "The unique identifier of the ruleset to test." | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"body": { | ||
"description": "The match criteria to test against the ruleset", | ||
"required": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.