Get an ES|QL view Generally available; Added in 9.4.0

GET /_query/view/{name}

All methods and paths for this operation:

GET /_query/view

GET /_query/view/{name}

Returns one or more stored views. A reserved view includes reserved set to true.

Required authorization

  • Index privileges: read_view_metadata
Define reusable queries with E...

Path parameters

  • name string | array[string] Required

    The comma-separated view names to retrieve.

Responses

  • 200 application/json
    Hide response attribute Show response attribute object
    • views array[object] Required

      A non-materialized ES|QL view.

      Hide views attributes Show views attributes object

      A non-materialized ES|QL view.

      • name string Required

        The name of the ES|QL view

      • query string Required

        The ES|QL query

      • description string Generally available; Added in 9.6.0

        A free-text description of the view.

      • reserved boolean Generally available; Added in 9.6.0

        Whether this view is reserved.

        Elasticsearch creates reserved views. They can be queried and read like any other view. They cannot be created, updated, or deleted through the views API. The response includes this field only when the value is true.

GET /_query/view/{name}
GET /_query/view/country_addresses
resp = client.esql.get_view(
    name="country_addresses",
)
const response = await client.esql.getView({
  name: "country_addresses",
});
response = client.esql.get_view(
  name: "country_addresses"
)
$resp = $client->esql()->getView([
    "name" => "country_addresses",
]);
curl -X GET -H "Authorization: ApiKey $ELASTIC_API_KEY" "$ELASTICSEARCH_URL/_query/view/country_addresses"
var response = await client.Esql
    .GetViewAsync(d1 => d1
        .Name(new[] { "country_addresses" })
    );
Response examples (200)
The response contains the requested view.
{
  "views": [
    {
      "name": "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"
    }
  ]
}
A reserved view includes reserved set to true. This view is created when anomaly detection results exist.
{
  "views": [
    {
      "name": ".ml-anomalies",
      "query": """
        FROM .ml-anomalies-* METADATA _index
        | WHERE result_type IN ("bucket", "record", "influencer")
        | EVAL score = COALESCE(anomaly_score, record_score, influencer_score),
               initial_score = COALESCE(initial_anomaly_score, initial_record_score, initial_influencer_score)
        | KEEP timestamp,
               event.ingested,
               job_id,
               result_type,
               is_interim,
               score,
               initial_score,
               bucket_span,
               function,
               function_description,
               field_name,
               by_field_name,
               by_field_value,
               over_field_name,
               over_field_value,
               partition_field_name,
               partition_field_value,
               influencer_field_name,
               influencer_field_value,
               detector_index,
               actual,
               typical,
               event_count,
               processing_time_ms,
               _index
      """,
      "description": "View that contains the results of machine learning anomaly detection jobs.",
      "reserved": true
    }
  ]
}