mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-25 07:37:19 -04:00
* Mark query rules APIs as stable * Remove preview label from docs * Update docs/changelog/110004.yaml
95 lines
2.8 KiB
Text
95 lines
2.8 KiB
Text
[role="xpack"]
|
|
[[query-dsl-rule-query]]
|
|
=== Rule query
|
|
|
|
++++
|
|
<titleabbrev>Rule</titleabbrev>
|
|
++++
|
|
|
|
[WARNING]
|
|
====
|
|
`rule_query` was renamed to `rule` in 8.15.0.
|
|
The old syntax using `rule_query` and `ruleset_id` is deprecated and will be removed in a future release, so it is strongly advised to migrate existing rule queries to the new API structure.
|
|
====
|
|
|
|
Applies <<query-rules-apis,query rules>> to the query before returning results.
|
|
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.
|
|
All matching rules are applied in the order in which they appear in the query ruleset.
|
|
|
|
[NOTE]
|
|
====
|
|
To use the rule query, you first need a defined set of query rules.
|
|
Use the <<query-rules-apis, query rules management APIs>> to create and manage query rules.
|
|
For more information and examples see <<search-using-query-rules>>.
|
|
====
|
|
|
|
==== Example request
|
|
|
|
////
|
|
|
|
[source,console]
|
|
--------------------------------------------------
|
|
PUT _query_rules/my-ruleset
|
|
{
|
|
"rules": [
|
|
{
|
|
"rule_id": "my-rule1",
|
|
"type": "pinned",
|
|
"criteria": [
|
|
{
|
|
"type": "exact",
|
|
"metadata": "user_query",
|
|
"values": ["puggles"]
|
|
}
|
|
],
|
|
"actions": {
|
|
"ids": [ "id1" ]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
--------------------------------------------------
|
|
// TESTSETUP
|
|
|
|
[source,console]
|
|
--------------------------------------------------
|
|
DELETE _query_rules/my-ruleset
|
|
--------------------------------------------------
|
|
// TEARDOWN
|
|
|
|
////
|
|
|
|
[source,console]
|
|
--------------------------------------------------
|
|
GET /_search
|
|
{
|
|
"query": {
|
|
"rule": {
|
|
"match_criteria": {
|
|
"user_query": "pugs"
|
|
},
|
|
"ruleset_ids": ["my-ruleset"],
|
|
"organic": {
|
|
"match": {
|
|
"description": "puggles"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
[[rule-query-top-level-parameters]]
|
|
==== Top-level parameters for `rule_query`
|
|
|
|
`ruleset_ids`::
|
|
(Required, array) An array of one or more unique <<query-rules-apis, query ruleset>> ID with query-based rules to match and apply as applicable.
|
|
Rulesets and their associated rules are evaluated in the order in which they are specified in the query and ruleset.
|
|
The maximum number of rulesets to specify is 10.
|
|
`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.
|