Skip to content

Commit c4d7657

Browse files
authored
Document dictionary parameter for Search Applications (#97501) (#97810)
* Document dictionary parameter for Search Applications * Address PR feedback
1 parent 9e281d6 commit c4d7657

File tree

1 file changed

+90
-1
lines changed

1 file changed

+90
-1
lines changed

docs/reference/search-application/apis/put-search-application.asciidoc

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ The <<search-template,search template>> associated with this search application.
4949
- The template may be modified with subsequent <<put-search-application,put search application>> requests.
5050
- If no template is specified when creating a search application, or if a template is removed from a search application, we use the <<query-string-query-ex-request,query_string>> defined in the template examples as a default.
5151
- This template will be used by the <<search-application-search,search application search>> API to execute searches.
52+
- The template accepts an optional `dictionary` parameter which defines a https://json-schema.org[JSON schema] used for validating parameters sent to the <<search-application-search,search application search>> API.
53+
54+
.Properties of `<template>`
55+
[%collapsible%open]
56+
=====
57+
58+
`script`::
59+
(Required, object)
60+
The associated mustache template.
61+
62+
`dictionary`::
63+
(Optional, object)
64+
The dictionary used to validate the parameters used with the <<search-application-search, search application search>> API. The dictionary must be a valid JSON schema.
65+
If `dictionary` is not specified, then the parameters will not be validated before being applied in the template.
66+
=====
5267
====
5368

5469

@@ -85,12 +100,69 @@ PUT _application/search_application/my-app?create
85100
"query_string": "*",
86101
"default_field": "*"
87102
}
103+
},
104+
"dictionary": {
105+
"properties": {
106+
"query_string": {
107+
"type": "string"
108+
},
109+
"default_field": {
110+
"type": "string",
111+
"enum": [
112+
"title",
113+
"description"
114+
]
115+
},
116+
"additionalProperties": false
117+
},
118+
"required": [
119+
"query_string"
120+
]
88121
}
89122
}
90123
}
91124
----
92125
// TEST[skip:TBD]
93126

127+
When the above `dictionary` parameter is specified, the <<search-application-search, search application search>> API will perform the following parameter validation:
128+
129+
* It accepts only the `query_string` and `default_field` parameters
130+
* It verifies that `query_string` and `default_field` are both strings
131+
* It accepts `default_field` only if it takes the values `title` or `description`
132+
133+
If the parameters are not valid, the the <<search-application-search, search application search>> API will return an error.
134+
[source,console]
135+
----
136+
POST _application/search_application/my-app/_search
137+
{
138+
"params": {
139+
"default_field": "author",
140+
"query_string": "Jane"
141+
}
142+
}
143+
----
144+
// TEST[skip:TBD]
145+
146+
In the above example, the value of the `default_field` parameter is not valid, therefore Elasticsearch will return an error:
147+
148+
[source,console-result]
149+
----
150+
{
151+
"error": {
152+
"root_cause": [
153+
{
154+
"type": "validation_exception",
155+
"reason": "Validation Failed: 1: $.default_field: does not have a value in the enumeration [title, description];"
156+
}
157+
],
158+
"type": "validation_exception",
159+
"reason": "Validation Failed: 1: $.default_field: does not have a value in the enumeration [title, description];"
160+
},
161+
"status": 400
162+
}
163+
----
164+
// TEST[skip:TBD]
165+
94166
The following example creates or updates an existing Search Application called `my-app`:
95167

96168
[source,console]
@@ -112,9 +184,26 @@ PUT _application/search_application/my-app
112184
"query_string": "*",
113185
"default_field": "*"
114186
}
187+
},
188+
"dictionary": {
189+
"properties": {
190+
"query_string": {
191+
"type": "string"
192+
},
193+
"default_field": {
194+
"type": "string",
195+
"enum": [
196+
"title",
197+
"description"
198+
]
199+
},
200+
"additionalProperties": false
201+
},
202+
"required": [
203+
"query_string"
204+
]
115205
}
116206
}
117207
}
118208
----
119209
// TEST[skip:TBD]
120-

0 commit comments

Comments
 (0)