---
type: api
title: Create a data view
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/kibana/operation/operation-post-data-views-v2
resource: https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/kibana/operation/operation-post-data-views-v2
products:
  - Kibana
---

# Create a data view

Authentication: required

Availability: Planned

- Server: `https://{kibana_url}`

## Paths

- `POST` `/api/data_views/v2`
- `POST` `/s/{space_id}/api/data_views/v2`

#### Path parameters

- `space_id` (string) — optional
  An identifier for the space. If `space_id` is not provided in the URL, the default space is used. Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

## Description

Creates a data view and returns it. Kibana generates the data view ID. If a data view with the same name already exists, the request fails with a conflict.

## Required authorization

- Privileges: `indexPatterns:manage`

## Header parameters

- `kbn-xsrf` (string) — required
  A required header to protect against CSRF attacks

## Request body

`application/json`

- `allow_hidden_indices` (boolean) — optional
  When `true`, allows the data view to match hidden indices.
- `field_filters` (string[] · max items: 10000) — optional
  Field filters can be used to exclude one or more fields when fetching a document. They may contain wildcards, such as `user*` which filters fields starting with 'user'.
- `field_settings` (map string to anyOf) — optional
  Settings for individual fields, keyed by field name. To change how Kibana displays a field from the backing indices, set its label, description, format, or popularity. To define a runtime field, use the runtime field name and set `type`.
- `index_pattern` (string · min length: 1) — required
  The index pattern (Elasticsearch index expression) to use as the data source. Example: "my-index-*".
- `name` (string · min length: 1 · max length: 256) — optional
  The name of the data view. Example: "Sample data view".
- `time_field` (string) — optional
  The name of the time field in the index. Used for time-based filtering. Example: "@timestamp".

## Responses

#### `201`

The data view was created.

`application/json`

- `data` (object)
  Defines an stored data source with a mandatory index pattern and optional settings like id, name, show hidden indices and field settings.
  - `allow_hidden_indices` (boolean)
    When `true`, allows the data view to match hidden indices.
  - `field_filters` (string[] · max items: 10000)
    Field filters can be used to exclude one or more fields when fetching a document. They may contain wildcards, such as `user*` which filters fields starting with 'user'.
  - `field_settings` (map string to anyOf)
    Settings for individual fields, keyed by field name. To change how Kibana displays a field from the backing indices, set its label, description, format, or popularity. To define a runtime field, use the runtime field name and set `type`.
  - `id` (string · min length: 1 · max length: 256)
    Kibana provides a unique identifier for each data view, or you can create your own.
  - `index_pattern` (string · min length: 1)
    The index pattern (Elasticsearch index expression) to use as the data source. Example: "my-index-*".
  - `name` (string · min length: 1 · max length: 256)
    The name of the data view. Example: "Sample data view".
  - `time_field` (string)
    The name of the time field in the index. Used for time-based filtering. Example: "@timestamp".
- `id` (string · max length: 1000)
  The ID of the data view.
- `meta` (object)
  Metadata about the data view.
  - `created_at` (string)
    Timestamp when the object was created (ISO 8601).
  - `created_by` (string)
    User profile ID of the user who created the object.
  - `managed` (boolean)
    When `true`, the object is managed by Kibana and cannot be edited by users.
  - `owner` (string)
    Identifier of the plugin or team that owns this object.
  - `spaces` (string[] · max items: 100)
    The IDs of the spaces where the data view is available.
  - `updated_at` (string)
    Timestamp when the object was last updated (ISO 8601).
  - `updated_by` (string)
    User profile ID of the user who last updated the object.
  - `version` (string)
    Internal version identifier for optimistic concurrency control.
#### `400`

The request is invalid, for example when a field format type does not exist.

#### `403`

forbidden

#### `409`

A data view with the same name already exists.

## Code examples

#### Console

```console
POST kbn:/api/data_views/v2
{
  "index_pattern": "logs-*",
  "name": "Web logs",
  "time_field": "@timestamp"
}
```

#### curl

```curl
curl -X POST "${KIBANA_URL}/api/data_views/v2" \
  -H "kbn-xsrf: true" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "index_pattern": "logs-*",
    "name": "Web logs",
    "time_field": "@timestamp"
  }'
```

## Response examples

#### Data view response

`application/json`

```json
{
  "data": {
    "index_pattern": "logs-*",
    "name": "Web logs",
    "time_field": "@timestamp"
  },
  "id": "c0ffee00-d57a-11ef-9a52-4f3c2a8d0e1b",
  "meta": {
    "managed": false,
    "spaces": [
      "default"
    ],
    "version": "WzEsMV0="
  }
}
```

