mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-25 07:37:19 -04:00
136 lines
2.9 KiB
Text
136 lines
2.9 KiB
Text
[role="xpack"]
|
|
[[get-query-rule]]
|
|
=== Get query rule
|
|
|
|
++++
|
|
<titleabbrev>Get query rule</titleabbrev>
|
|
++++
|
|
|
|
.New API reference
|
|
[sidebar]
|
|
--
|
|
For the most up-to-date API details, refer to {api-es}/group/endpoint-query_rules[Query rules APIs].
|
|
--
|
|
|
|
Retrieves information about an individual query rule within a query ruleset.
|
|
|
|
[[get-query-rule-request]]
|
|
==== {api-request-title}
|
|
|
|
`GET _query_rules/<ruleset_id>/_rule/<rule_id>`
|
|
|
|
[[get-query-rule-prereq]]
|
|
==== {api-prereq-title}
|
|
|
|
Requires the `manage_search_query_rules` privilege.
|
|
|
|
[[get-query-rule-path-params]]
|
|
==== {api-path-parms-title}
|
|
|
|
`<ruleset_id>`::
|
|
(Required, string)
|
|
|
|
`<rule_id>`::
|
|
(Required, string)
|
|
|
|
[[get-query-rule-response-codes]]
|
|
==== {api-response-codes-title}
|
|
|
|
`400`::
|
|
Missing `ruleset_id` or `rule_id`, or both.
|
|
|
|
`404` (Missing resources)::
|
|
Either no query ruleset matching `ruleset_id` could be found, or no rule matching `rule_id` could be found within that ruleset.
|
|
|
|
[[get-query-rule-example]]
|
|
==== {api-examples-title}
|
|
|
|
The following example gets the query rule with ID `my-rule1` from the ruleset named `my-ruleset`:
|
|
|
|
////
|
|
|
|
[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]
|
|
----
|
|
GET _query_rules/my-ruleset/_rule/my-rule1
|
|
----
|
|
|
|
A sample response:
|
|
|
|
[source,console-result]
|
|
----
|
|
{
|
|
"rule_id": "my-rule1",
|
|
"type": "pinned",
|
|
"criteria": [
|
|
{
|
|
"type": "contains",
|
|
"metadata": "query_string",
|
|
"values": [ "pugs", "puggles" ]
|
|
}
|
|
],
|
|
"actions": {
|
|
"ids": [
|
|
"id1",
|
|
"id2"
|
|
]
|
|
}
|
|
}
|
|
----
|