Create or update a search application
Beta; Added in 8.8.0
Required authorization
- Index privileges:
manage
- Cluster privileges:
manage_search_application
Path parameters
-
name
string Required The name of the search application to be created or updated.
Query parameters
-
create
boolean If
true
, this request cannot replace or update existing Search Applications.
Body
Required
-
indices
array[string] Required Indices that are part of the Search Application.
-
analytics_collection_name
string -
template
object
PUT
/_application/search_application/{name}
Console
PUT _application/search_application/my-app
{
"indices": [ "index1", "index2" ],
"template": {
"script": {
"source": {
"query": {
"query_string": {
"query": "{{query_string}}",
"default_field": "{{default_field}}"
}
}
},
"params": {
"query_string": "*",
"default_field": "*"
}
},
"dictionary": {
"properties": {
"query_string": {
"type": "string"
},
"default_field": {
"type": "string",
"enum": [
"title",
"description"
]
},
"additionalProperties": false
},
"required": [
"query_string"
]
}
}
}
resp = client.search_application.put(
name="my-app",
search_application={
"indices": [
"index1",
"index2"
],
"template": {
"script": {
"source": {
"query": {
"query_string": {
"query": "{{query_string}}",
"default_field": "{{default_field}}"
}
}
},
"params": {
"query_string": "*",
"default_field": "*"
}
},
"dictionary": {
"properties": {
"query_string": {
"type": "string"
},
"default_field": {
"type": "string",
"enum": [
"title",
"description"
]
},
"additionalProperties": False
},
"required": [
"query_string"
]
}
}
},
)
const response = await client.searchApplication.put({
name: "my-app",
search_application: {
indices: ["index1", "index2"],
template: {
script: {
source: {
query: {
query_string: {
query: "{{query_string}}",
default_field: "{{default_field}}",
},
},
},
params: {
query_string: "*",
default_field: "*",
},
},
dictionary: {
properties: {
query_string: {
type: "string",
},
default_field: {
type: "string",
enum: ["title", "description"],
},
additionalProperties: false,
},
required: ["query_string"],
},
},
},
});
response = client.search_application.put(
name: "my-app",
body: {
"indices": [
"index1",
"index2"
],
"template": {
"script": {
"source": {
"query": {
"query_string": {
"query": "{{query_string}}",
"default_field": "{{default_field}}"
}
}
},
"params": {
"query_string": "*",
"default_field": "*"
}
},
"dictionary": {
"properties": {
"query_string": {
"type": "string"
},
"default_field": {
"type": "string",
"enum": [
"title",
"description"
]
},
"additionalProperties": false
},
"required": [
"query_string"
]
}
}
}
)
$resp = $client->searchApplication()->put([
"name" => "my-app",
"body" => [
"indices" => array(
"index1",
"index2",
),
"template" => [
"script" => [
"source" => [
"query" => [
"query_string" => [
"query" => "{{query_string}}",
"default_field" => "{{default_field}}",
],
],
],
"params" => [
"query_string" => "*",
"default_field" => "*",
],
],
"dictionary" => [
"properties" => [
"query_string" => [
"type" => "string",
],
"default_field" => [
"type" => "string",
"enum" => array(
"title",
"description",
),
],
"additionalProperties" => false,
],
"required" => array(
"query_string",
),
],
],
],
]);
curl -X PUT -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"indices":["index1","index2"],"template":{"script":{"source":{"query":{"query_string":{"query":"{{query_string}}","default_field":"{{default_field}}"}}},"params":{"query_string":"*","default_field":"*"}},"dictionary":{"properties":{"query_string":{"type":"string"},"default_field":{"type":"string","enum":["title","description"]},"additionalProperties":false},"required":["query_string"]}}}' "$ELASTICSEARCH_URL/_application/search_application/my-app"
Request example
Run `PUT _application/search_application/my-app` to create or update a search application called `my-app`. When the dictionary parameter is specified, the 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 search application search API will return an error.
{
"indices": [ "index1", "index2" ],
"template": {
"script": {
"source": {
"query": {
"query_string": {
"query": "{{query_string}}",
"default_field": "{{default_field}}"
}
}
},
"params": {
"query_string": "*",
"default_field": "*"
}
},
"dictionary": {
"properties": {
"query_string": {
"type": "string"
},
"default_field": {
"type": "string",
"enum": [
"title",
"description"
]
},
"additionalProperties": false
},
"required": [
"query_string"
]
}
}
}