Stores an ES|QL query that runs whenever the view is referenced. A query that cannot be parsed is rejected. Replacing a reserved view fails.
Required authorization
- Index privileges:
create_view
Query parameters
-
Whether to analyze the view query and return a warning when validation fails.
Validation reports an unknown index or column, including an index the caller cannot read. The view is saved even when validation reports a problem. Failures unrelated to the query, such as an overloaded cluster, produce no warning.
Default value is
false.
PUT
/_query/view/{name}
Console
PUT /_query/view/country_addresses
{
"query": """
FROM addresses
| RENAME city.country.name AS country
| EVAL country = CASE(country == "United States of America", "United States", country)
| STATS count=COUNT() BY country
""",
"description": "Address counts by country"
}
resp = client.esql.put_view(
name="country_addresses",
query="\n FROM addresses\n | RENAME city.country.name AS country\n | EVAL country = CASE(country == \"United States of America\", \"United States\", country)\n | STATS count=COUNT() BY country\n ",
description="Address counts by country",
)
const response = await client.esql.putView({
name: "country_addresses",
query:
'\n FROM addresses\n | RENAME city.country.name AS country\n | EVAL country = CASE(country == "United States of America", "United States", country)\n | STATS count=COUNT() BY country\n ',
description: "Address counts by country",
});
response = client.esql.put_view(
name: "country_addresses",
body: {
"query": "\n FROM addresses\n | RENAME city.country.name AS country\n | EVAL country = CASE(country == \"United States of America\", \"United States\", country)\n | STATS count=COUNT() BY country\n ",
"description": "Address counts by country"
}
)
$resp = $client->esql()->putView([
"name" => "country_addresses",
"body" => [
"query" => "\n FROM addresses\n | RENAME city.country.name AS country\n | EVAL country = CASE(country == \"United States of America\", \"United States\", country)\n | STATS count=COUNT() BY country\n ",
"description" => "Address counts by country",
],
]);
curl -X PUT -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"query":"\n FROM addresses\n | RENAME city.country.name AS country\n | EVAL country = CASE(country == \"United States of America\", \"United States\", country)\n | STATS count=COUNT() BY country\n ","description":"Address counts by country"}' "$ELASTICSEARCH_URL/_query/view/country_addresses"
var response = await client.Esql
.PutViewAsync(name: "country_addresses", d1 => d1
.Description("Address counts by country")
.Query("\n FROM addresses\n | RENAME city.country.name AS country\n | EVAL country = CASE(country == \"United States of America\", \"United States\", country)\n | STATS count=COUNT() BY country\n ")
);
Request examples
Create a view of country counts
Create a view that normalizes country names and counts addresses by country.
{
"query": """
FROM addresses
| RENAME city.country.name AS country
| EVAL country = CASE(country == "United States of America", "United States", country)
| STATS count=COUNT() BY country
""",
"description": "Address counts by country"
}
Analyze the view query before saving it. When the query uses an unknown index or column, the response includes a warning and the view is still saved.
{
"query": """
FROM addresses
| RENAME city.country.name AS country
| EVAL country = CASE(country == "United States of America", "United States", country)
| STATS count=COUNT() BY country
""",
"description": "Address counts by country"
}
Response examples (200)
The view definition was stored successfully.
{
"acknowledged": true
}