Skip to content

Commit 66922fd

Browse files
kderussoleemthompo
andauthored
[Query Rules] clarify query rules API documentation (elastic#100732) (elastic#100825)
* Update example in query rules docs * Ensure GET docs are also consistent * Update docs/reference/query-rules/apis/put-query-ruleset.asciidoc --------- Co-authored-by: Liam Thompson <32779855+leemthompo@users.noreply.github.com>
1 parent 78ac64f commit 66922fd

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

docs/reference/query-rules/apis/get-query-ruleset.asciidoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ PUT _query_rules/my-ruleset
5252
"type": "pinned",
5353
"criteria": [
5454
{
55-
"type": "exact",
55+
"type": "contains",
5656
"metadata": "query_string",
57-
"values": [ "marvel" ]
57+
"values": [ "pugs", "puggles" ]
5858
}
5959
],
6060
"actions": {
@@ -69,9 +69,9 @@ PUT _query_rules/my-ruleset
6969
"type": "pinned",
7070
"criteria": [
7171
{
72-
"type": "exact",
72+
"type": "fuzzy",
7373
"metadata": "query_string",
74-
"values": [ "dc" ]
74+
"values": [ "rescue dogs" ]
7575
}
7676
],
7777
"actions": {
@@ -117,9 +117,9 @@ A sample response:
117117
"type": "pinned",
118118
"criteria": [
119119
{
120-
"type": "exact",
120+
"type": "contains",
121121
"metadata": "query_string",
122-
"values": [ "marvel" ]
122+
"values": [ "pugs", "puggles" ]
123123
}
124124
],
125125
"actions": {
@@ -134,9 +134,9 @@ A sample response:
134134
"type": "pinned",
135135
"criteria": [
136136
{
137-
"type": "exact",
137+
"type": "fuzzy",
138138
"metadata": "query_string",
139-
"values": [ "dc" ]
139+
"values": [ "rescue dogs" ]
140140
}
141141
],
142142
"actions": {

docs/reference/query-rules/apis/put-query-ruleset.asciidoc

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,27 @@ Requires the `manage_search_query_rules` privilege.
2222

2323
[role="child_attributes"]
2424
[[put-query-ruleset-request-body]]
25-
(Required, object)
26-
Contains parameters for a query ruleset:
25+
(Required, object) Contains parameters for a query ruleset:
2726

2827
==== {api-request-body-title}
28+
2929
`rules`::
30-
(Required, array of objects)
31-
The specific rules included in this query ruleset.
30+
(Required, array of objects) The specific rules included in this query ruleset.
3231

3332
Each rule must have the following information:
3433

35-
- `rule_id` (Required, string)
36-
A unique identifier for this rule.
37-
- `type` (Required, string)
38-
The type of rule. At this time only `pinned` query rule types are allowed.
39-
- `criteria` (Required, array of objects)
40-
The criteria that must be met for the rule to be applied. If multiple criteria are specified for a rule, all criteria must be met for the rule to be applied.
41-
- `actions` (Required, object)
42-
The actions to take when the rule is matched. The format of this action depends on the rule type.
34+
- `rule_id` (Required, string) A unique identifier for this rule.
35+
- `type` (Required, string) The type of rule.
36+
At this time only `pinned` query rule types are allowed.
37+
- `criteria` (Required, array of objects) The criteria that must be met for the rule to be applied.
38+
If multiple criteria are specified for a rule, all criteria must be met for the rule to be applied.
39+
- `actions` (Required, object) The actions to take when the rule is matched.
40+
The format of this action depends on the rule type.
4341

4442
Criteria must have the following information:
4543

46-
- `type` (Required, string)
47-
The type of criteria. The following criteria types are supported:
44+
- `type` (Required, string) The type of criteria.
45+
The following criteria types are supported:
4846
+
4947
--
5048
- `exact`
@@ -77,30 +75,32 @@ Only applicable for numerical values.
7775
- `always`
7876
Matches all queries, regardless of input.
7977
--
80-
- `metadata` (Optional, string)
81-
The metadata field to match against. Required for all criteria types except `global`.
82-
- `values` (Optional, array of strings)
83-
The values to match against the metadata field. Only one value must match for the criteria to be met. Required for all criteria types except `global`.
78+
- `metadata` (Optional, string) The metadata field to match against.
79+
This metadata will be used to match against `match_criteria` sent in the <<query-dsl-rule-query>>.
80+
Required for all criteria types except `global`.
81+
- `values` (Optional, array of strings) The values to match against the metadata field.
82+
Only one value must match for the criteria to be met.
83+
Required for all criteria types except `global`.
8484

8585
Actions depend on the rule type.
8686
For `pinned` rules, actions follow the format specified by the <<query-dsl-pinned-query,Pinned Query>>.
8787
The following actions are allowed:
8888

89-
- `ids` (Optional, array of strings)
90-
The The unique <<mapping-id-field, document IDs>> of the documents to pin.
91-
Only one of `ids` or `docs` may be specified, and at least one must be specified.
92-
- `docs` (Optional, array of objects)
93-
The documents to pin. Only one of `ids` or `docs` may be specified, and at least one must be specified.
94-
You can specify the following attributes for each document:
89+
- `ids` (Optional, array of strings) The unique <<mapping-id-field, document IDs>> of the documents to pin.
90+
Only one of `ids` or `docs` may be specified, and at least one must be specified.
91+
- `docs` (Optional, array of objects) The documents to pin.
92+
Only one of `ids` or `docs` may be specified, and at least one must be specified.
93+
You can specify the following attributes for each document:
9594
+
9695
--
97-
- `_index` (Required, string)
98-
The index of the document to pin.
99-
- `_id` (Required, string)
100-
The unique <<mapping-id-field, document ID>>.
96+
- `_index` (Required, string) The index of the document to pin.
97+
- `_id` (Required, string) The unique <<mapping-id-field, document ID>>.
10198
--
10299

103-
IMPORTANT: Due to limitations within <<query-dsl-pinned-query,Pinned queries>>, you can only pin documents using `ids` or `docs`, but cannot use both in single rule. It is advised to use one or the other in query rulesets, to avoid errors. Additionally, pinned queries have a maximum limit of 100 pinned hits. If multiple matching rules pin more than 100 documents, only the first 100 documents are pinned in the order they are specified in the ruleset.
100+
IMPORTANT: Due to limitations within <<query-dsl-pinned-query,Pinned queries>>, you can only pin documents using `ids` or `docs`, but cannot use both in single rule.
101+
It is advised to use one or the other in query rulesets, to avoid errors.
102+
Additionally, pinned queries have a maximum limit of 100 pinned hits.
103+
If multiple matching rules pin more than 100 documents, only the first 100 documents are pinned in the order they are specified in the ruleset.
104104

105105
[[put-query-ruleset-example]]
106106
==== {api-examples-title}
@@ -109,8 +109,8 @@ The following example creates a new query ruleset called `my-ruleset`.
109109

110110
Two rules are associated with `my-ruleset`:
111111

112-
- `my-rule1` will pin documents with IDs `id1` and `id2` when `user.query` exactly matches `marvel` _or_ `dc` **and** `user.country` exactly matches `us`.
113-
- `my-rule2` will pin documents from different, specified indices with IDs `id3` and `id4` when the `query_string` fuzzily matches `comic`.
112+
- `my-rule1` will pin documents with IDs `id1` and `id2` when `user_query` contains `pugs` _or_ `puggles` **and** `user_country` exactly matches `us`.
113+
- `my-rule2` will pin documents from different, specified indices with IDs `id3` and `id4` when the `query_string` fuzzily matches `rescue dogs`.
114114

115115
[source,console]
116116
----
@@ -123,12 +123,12 @@ PUT _query_rules/my-ruleset
123123
"criteria": [
124124
{
125125
"type": "contains",
126-
"metadata": "user.query",
127-
"values": [ "marvel", "dc" ]
126+
"metadata": "user_query",
127+
"values": [ "pugs", "puggles" ]
128128
},
129129
{
130130
"type": "exact",
131-
"metadata": "user.country",
131+
"metadata": "user_country",
132132
"values": [ "us" ]
133133
}
134134
],
@@ -145,8 +145,8 @@ PUT _query_rules/my-ruleset
145145
"criteria": [
146146
{
147147
"type": "fuzzy",
148-
"metadata": "query_string",
149-
"values": [ "comic" ]
148+
"metadata": "user_query",
149+
"values": [ "rescue dogs" ]
150150
}
151151
],
152152
"actions": {

0 commit comments

Comments
 (0)