Skip to content

Add Create or update query rule API call #109042

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
merged 16 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/109042.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 109042
summary: Add Create or update query rule API call
area: Application
type: enhancement
issues: [ ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"query_rule.put": {
"documentation": {
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/put-query-rule.html",
"description": "Creates or updates a query rule within a ruleset."
},
"stability": "experimental",
"visibility": "public",
"headers": {
"accept": [
"application/json"
],
"content_type": [
"application/json"
]
},
"url": {
"paths": [
{
"path": "/_query_rules/{ruleset_id}/{rule_id}",
"methods": [
"PUT"
],
"parts": {
"ruleset_id": {
"type": "string",
"description": "The unique identifier of the ruleset this rule should be added to. The ruleset will be created if it does not exist."
},
"rule_id": {
"type": "string",
"description": "The unique identifier of the rule to be created or updated."
}
}
}
]
},
"body": {
"description": "The query rule configuration, including the type of rule, the criteria to match the rule, and the action that should be taken if the rule matches.",
"required": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ static TransportVersion def(int id) {
public static final TransportVersion RANK_FEATURE_PHASE_ADDED = def(8_678_00_0);
public static final TransportVersion RANK_DOC_IN_SHARD_FETCH_REQUEST = def(8_679_00_0);
public static final TransportVersion SECURITY_SETTINGS_REQUEST_TIMEOUTS = def(8_680_00_0);
public static final TransportVersion QUERY_RULE_CRUD_API_PUT = def(8_681_00_0);

/*
* STOP! READ THIS FIRST! No, really,
Expand Down
15 changes: 14 additions & 1 deletion x-pack/plugin/ent-search/qa/rest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@ dependencies {

restResources {
restApi {
include '_common', 'bulk', 'cluster', 'connector', 'nodes', 'indices', 'index', 'query_ruleset', 'search_application', 'xpack', 'security', 'search', 'ml'
include '_common',
'bulk',
'cluster',
'connector',
'nodes',
'indices',
'index',
'query_ruleset',
'query_rule',
'search_application',
'xpack',
'security',
'search',
'ml'
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@

setup:
- requires:
cluster_features: ["gte_v8.10.0"]
cluster_features: [ "gte_v8.10.0" ]
reason: Introduced in 8.10.0

---
teardown:
- do:
query_ruleset.delete:
ruleset_id: test-ruleset
ignore: 404

- do:
query_ruleset.delete:
ruleset_id: test-query-ruleset-recreating
ignore: 404

---
'Create Query Ruleset':
- do:
Expand All @@ -16,7 +27,7 @@ setup:
criteria:
- type: exact
metadata: query_string
values: [elastic]
values: [ elastic ]
actions:
ids:
- 'id1'
Expand All @@ -26,7 +37,7 @@ setup:
criteria:
- type: exact
metadata: query_string
values: [kibana]
values: [ kibana ]
actions:
docs:
- '_index': 'test-index1'
Expand All @@ -47,7 +58,7 @@ setup:
criteria:
- type: exact
metadata: query_string
values: [elastic]
values: [ elastic ]
actions:
ids:
- 'id1'
Expand All @@ -57,7 +68,7 @@ setup:
criteria:
- type: exact
metadata: query_string
values: [kibana]
values: [ kibana ]
actions:
docs:
- '_index': 'test-index1'
Expand All @@ -77,7 +88,7 @@ setup:
criteria:
type: 'exact'
metadata: 'query_string'
values: ['elastic']
values: [ 'elastic' ]
actions:
ids:
- 'id1'
Expand All @@ -94,7 +105,7 @@ setup:
criteria:
type: 'exact'
metadata: 'query_string'
values: ['elastic']
values: [ 'elastic' ]
actions:
ids:
- 'id2'
Expand All @@ -118,7 +129,7 @@ setup:
criteria:
type: 'exact'
metadata: 'query_string'
values: ['elastic']
values: [ 'elastic' ]
actions:
ids:
- 'id1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
setup:
- requires:
cluster_features: ["gte_v8.10.0"]
cluster_features: [ "gte_v8.10.0" ]
reason: Introduced in 8.10.0
- do:
query_ruleset.put:
Expand All @@ -12,7 +12,7 @@ setup:
criteria:
- type: exact
metadata: query_string
values: [elastic]
values: [ elastic ]
actions:
ids:
- 'id1'
Expand All @@ -22,7 +22,7 @@ setup:
criteria:
- type: exact
metadata: query_string
values: [kibana]
values: [ kibana ]
actions:
ids:
- 'id3'
Expand All @@ -38,7 +38,7 @@ setup:
criteria:
- type: exact
metadata: query_string
values: [elastic]
values: [ elastic ]
actions:
ids:
- 'id1'
Expand All @@ -48,7 +48,7 @@ setup:
criteria:
- type: exact
metadata: query_string
values: [kibana]
values: [ kibana ]
actions:
ids:
- 'id3'
Expand All @@ -58,7 +58,7 @@ setup:
criteria:
- type: exact
metadata: query_string
values: [logstash]
values: [ logstash ]
actions:
ids:
- 'id5'
Expand All @@ -74,7 +74,7 @@ setup:
criteria:
- type: exact
metadata: query_string
values: [elastic]
values: [ elastic ]
actions:
ids:
- 'id1'
Expand All @@ -84,7 +84,7 @@ setup:
criteria:
- type: exact
metadata: query_string
values: [kibana]
values: [ kibana ]
actions:
ids:
- 'id3'
Expand All @@ -94,7 +94,7 @@ setup:
criteria:
- type: exact
metadata: query_string
values: [logstash]
values: [ logstash ]
actions:
ids:
- 'id5'
Expand All @@ -104,11 +104,32 @@ setup:
criteria:
- type: exact
metadata: query_string
values: [beats]
values: [ beats ]
actions:
ids:
- 'id7'
- 'id8'
---
teardown:
- do:
query_ruleset.delete:
ruleset_id: test-query-ruleset-1
ignore: 404

- do:
query_ruleset.delete:
ruleset_id: test-query-ruleset-2
ignore: 404

- do:
query_ruleset.delete:
ruleset_id: test-query-ruleset-3
ignore: 404

- do:
query_ruleset.delete:
ruleset_id: a-test-query-ruleset-with-lots-of-criteria
ignore: 404

---
"List Query Rulesets":
Expand Down Expand Up @@ -263,3 +284,16 @@ setup:
prefix: 1
suffix: 1
always: 1

---
'List Query Rulesets - Insufficient privilege':
- skip:
features: headers

- do:
catch: forbidden
headers: { Authorization: "Basic ZW50c2VhcmNoLXVzZXI6ZW50c2VhcmNoLXVzZXItcGFzc3dvcmQ=" } # user
query_ruleset.list: { }

- match: { error.type: 'security_exception' }

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
setup:
- requires:
cluster_features: ["gte_v8.10.0"]
cluster_features: [ "gte_v8.10.0" ]
reason: Introduced in 8.10.0
- do:
query_ruleset.put:
Expand All @@ -12,7 +12,7 @@ setup:
criteria:
- type: exact
metadata: query_string
values: [elastic]
values: [ elastic ]
actions:
ids:
- 'id1'
Expand All @@ -37,3 +37,16 @@ setup:
catch: "missing"
query_ruleset.delete:
ruleset_id: test-nonexistent-query-ruleset

---
'Delete Query Ruleset - Insufficient privilege':
- skip:
features: headers

- do:
catch: forbidden
headers: { Authorization: "Basic ZW50c2VhcmNoLXVzZXI6ZW50c2VhcmNoLXVzZXItcGFzc3dvcmQ=" } # user
query_ruleset.delete:
ruleset_id: test-query-ruleset-to-delete

- match: { error.type: 'security_exception' }
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ setup:
ids:
- 'doc6'

---
teardown:
- do:
query_ruleset.delete:
ruleset_id: test-ruleset
ignore: 404

- do:
query_ruleset.delete:
ruleset_id: another-test-ruleset
ignore: 404

- do:
query_ruleset.delete:
ruleset_id: combined-ruleset
ignore: 404

---
"Perform a rule query specifying a ruleset that does not exist":
- do:
Expand Down
Loading