81 lines
2.0 KiB
Plaintext
81 lines
2.0 KiB
Plaintext
|
[role="xpack"]
|
||
|
[[query-dsl-rule-query]]
|
||
|
=== Rule query
|
||
|
++++
|
||
|
<titleabbrev>Rule</titleabbrev>
|
||
|
++++
|
||
|
|
||
|
preview::[]
|
||
|
|
||
|
Applies rules configured in the <<query-rules-apis, Query Rules API>> to the query.
|
||
|
This feature is used to promote documents in the manner of a <<query-dsl-pinned-query>> based on matching defined rules.
|
||
|
If no matching query rules are defined, the "organic" matches for the query are returned.
|
||
|
|
||
|
==== Example request
|
||
|
|
||
|
////
|
||
|
|
||
|
[source,console]
|
||
|
--------------------------------------------------
|
||
|
PUT _query_rules/my-ruleset
|
||
|
{
|
||
|
"rules": [
|
||
|
{
|
||
|
"rule_id": "my-rule1",
|
||
|
"type": "pinned",
|
||
|
"criteria": [
|
||
|
{
|
||
|
"type": "exact",
|
||
|
"metadata": "query_string",
|
||
|
"values": ["pugs"]
|
||
|
}
|
||
|
],
|
||
|
"actions": {
|
||
|
"ids": [ "id1" ]
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
--------------------------------------------------
|
||
|
// TESTSETUP
|
||
|
|
||
|
[source,console]
|
||
|
--------------------------------------------------
|
||
|
DELETE _query_rules/my-ruleset
|
||
|
--------------------------------------------------
|
||
|
// TEARDOWN
|
||
|
|
||
|
////
|
||
|
|
||
|
[source,console]
|
||
|
--------------------------------------------------
|
||
|
GET /_search
|
||
|
{
|
||
|
"query": {
|
||
|
"rule_query": {
|
||
|
"match_criteria": {
|
||
|
"query_string": "pugs"
|
||
|
},
|
||
|
"ruleset_id": "my-ruleset",
|
||
|
"organic": {
|
||
|
"match": {
|
||
|
"description": "pugs"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
--------------------------------------------------
|
||
|
|
||
|
[[rule-query-top-level-parameters]]
|
||
|
==== Top-level parameters for `rule_query`
|
||
|
|
||
|
`ruleset_id`::
|
||
|
(Required, string) A unique <<query-rules-apis, query ruleset>> ID with query-based rules to match and apply as applicable.
|
||
|
`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.
|
||
|
`organic`::
|
||
|
(Required, object) Any choice of <<query-dsl, query>> used to return results, that may be modified by matching query rules.
|
||
|
If no query rules are matched and applied, this query will be executed with no modification.
|