Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ The <<search-template,search template>> associated with this search application.
- The template may be modified with subsequent <<put-search-application,put search application>> requests.
- 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.
- This template will be used by the <<search-application-search,search application search>> API to execute searches.
- 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.

.Properties of `<template>`
[%collapsible%open]
=====

`script`::
(Required, object)
The associated mustache template.

`dictionary`::
(Optional, object)
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.
If `dictionary` is not specified, then the parameters will not be validated before being applied in the template.
=====
====


Expand Down Expand Up @@ -85,12 +100,69 @@ PUT _application/search_application/my-app?create
"query_string": "*",
"default_field": "*"
}
},
"dictionary": {
"properties": {
"query_string": {
"type": "string"
},
"default_field": {
"type": "string",
"enum": [
"title",
"description"
]
},
"additionalProperties": false
},
"required": [
"query_string"
]
}
}
}
----
// TEST[skip:TBD]

When the above `dictionary` parameter is specified, the <<search-application-search, search application search>> API will perform the following parameter validation:

* It accepts only the `query_string` and `default_field` parameters
* It verifies that `query_string` and `default_field` are both strings
* It accepts `default_field` only if it takes the values `title` or `description`

If the parameters are not valid, the the <<search-application-search, search application search>> API will return an error.
[source,console]
----
POST _application/search_application/my-app/_search
{
"params": {
"default_field": "author",
"query_string": "Jane"
}
}
----
// TEST[skip:TBD]

In the above example, the value of the `default_field` parameter is not valid, therefore Elasticsearch will return an error:

[source,console-result]
----
{
"error": {
"root_cause": [
{
"type": "validation_exception",
"reason": "Validation Failed: 1: $.default_field: does not have a value in the enumeration [title, description];"
}
],
"type": "validation_exception",
"reason": "Validation Failed: 1: $.default_field: does not have a value in the enumeration [title, description];"
},
"status": 400
}
----
// TEST[skip:TBD]

The following example creates or updates an existing Search Application called `my-app`:

[source,console]
Expand All @@ -112,9 +184,26 @@ PUT _application/search_application/my-app
"query_string": "*",
"default_field": "*"
}
},
"dictionary": {
"properties": {
"query_string": {
"type": "string"
},
"default_field": {
"type": "string",
"enum": [
"title",
"description"
]
},
"additionalProperties": false
},
"required": [
"query_string"
]
}
}
}
----
// TEST[skip:TBD]