-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Add a query rules tester API call #114168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kderusso
merged 9 commits into
elastic:main
from
kderusso:kderusso/query-rules-tester-api
Oct 14, 2024
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
df6dfa8
Add a query rules tester API call
kderusso 1bc085b
Update docs/changelog/114168.yaml
kderusso 2d2c24b
Wrap client call in async with origin
kderusso e46ae97
Remove unused param
kderusso 339297b
PR feedback
kderusso 9784406
Merge from main
kderusso c5fa25e
Remove redundant test
kderusso ba4708f
CI workaround - add ent-search as ml dependency so it can find node f…
kderusso 0bf2bfd
Merge from main
kderusso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there other docs/guides where we want to refer to this API as a way to test/troubleshoot a query rules set? (can be done as a follow up)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to do that as a followup. This is being launched in preview right now, because there may be evolving requirements. I think when it gets closer to beta or GA is when it would be most helpful to promote this more, WDYT?