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

# Create a data view

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

## Paths

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

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/kibana-serverless/authentication#apikeyauth)

## Description

Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

Create a data view. Data views identify the Elasticsearch data you want to explore and visualize. They can point to one or more data streams, indices, or index aliases, and use optional runtime fields to compute values at query time. Note that data views are not required for ES|QL-based visualizations. To learn more, refer to the [data views documentation](https://www.elastic.co/docs/explore-analyze/find-and-organize/data-views).

## Request Body

`application/json`

- `data_view` (object) — required
  The data view object.
  - `allowNoIndex` (boolean) — optional
    Allows the data view saved object to exist before the data is available. Defaults to `false`.
  - `fieldAttrs` (map string to object) — optional
    Map values ({})
    - `count` (integer) — optional
      Popularity count for the field.
    - `customDescription` (string · max: 300) — optional
      Custom description for the field.
    - `customLabel` (string) — optional
      Custom label for the field.
  - `fieldFormats` (object) — optional
    A map of field formats by field name.
  - `fields` (object) — optional
  - `id` (string) — optional
  - `name` (string) — optional
    The data view name.
  - `namespaces` ([] object) — optional
    An array of space identifiers for sharing the data view between multiple spaces.
  - `runtimeFieldMap` (map string to object) — optional
    Map values ({})
    - `script` (object) — required
      - `source` (string) — optional
        Script for the runtime field.
    - `type` (string) — required
      Mapping type of the runtime field.
  - `sourceFilters` ([] object) — optional
    The array of field names you want to filter out in Discover.
    - `value` (string) — required
  - `timeFieldName` (string) — optional
    The timestamp field name, which you use for time-based data views.
  - `title` (string) — required
    Comma-separated list of data streams, indices, and aliases that you want to search. Supports wildcards (`*`).
  - `type` (string) — optional
    When set to `rollup`, identifies the rollup data views.
  - `typeMeta` ({}) — optional
    When you use rollup indices, contains the field list for the rollup data view API endpoints.
    - `aggs` (object) — required
      A map of rollup restrictions by aggregation type and field name.
    - `params` (object) — required
      Properties for retrieving rollup fields.
  - `version` (string) — optional
- `override` (boolean · default: false) — optional
  Override an existing data view if a data view with the provided title already exists.

## Responses

#### `200`

Indicates a successful call.

`application/json`

- `data_view` (object)
  - `allowNoIndex` (boolean)
    Allows the data view saved object to exist before the data is available. Defaults to `false`.
  - `fieldAttrs` (map string to object)
    Map values ({})
    - `count` (integer)
      Popularity count for the field.
    - `customDescription` (string · max: 300)
      Custom description for the field.
    - `customLabel` (string)
      Custom label for the field.
  - `fieldFormats` (object)
    A map of field formats by field name.
  - `fields` (object)
  - `id` (string)
  - `name` (string)
    The data view name.
  - `namespaces` ([] object)
    An array of space identifiers for sharing the data view between multiple spaces.
  - `runtimeFieldMap` (map string to object)
    Map values ({})
    - `script` (object)
      - `source` (string)
        Script for the runtime field.
    - `type` (string)
      Mapping type of the runtime field.
  - `sourceFilters` ([] object)
    The array of field names you want to filter out in Discover.
    - `value` (string)
  - `timeFieldName` (string)
    The timestamp field name, which you use for time-based data views.
  - `title` (string)
    Comma-separated list of data streams, indices, and aliases that you want to search. Supports wildcards (`*`).
  - `typeMeta` ({}) — nullable
    When you use rollup indices, contains the field list for the rollup data view API endpoints.
    - `aggs` (object)
      A map of rollup restrictions by aggregation type and field name.
    - `params` (object)
      Properties for retrieving rollup fields.
  - `version` (string)
#### `400`

Bad request

`application/json`

- `error` (string)
- `message` (string)
- `statusCode` (number)
## Code Examples

#### Console

```console
POST kbn://api/data_views/data_view
{"data_view":{"title":"logstash-*","name":"My Logstash data view"}}
```

#### curl

```curl
curl \
  -X POST "${KIBANA_URL}/api/data_views/data_view" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "kbn-xsrf: true" \
  -H "Content-Type: application/json" \
  -d '{"data_view":{"title":"logstash-*","name":"My Logstash data view"}}'
```

## Response Examples

#### The create data view API returns a JSON object that contains details about the new data view.

The response includes the full data view specification, including auto-generated fields such as the unique identifier and version.

```json
{
  "data_view": {
    "allowNoIndex": false,
    "fieldAttrs": {},
    "fieldFormats": {},
    "fields": {
      "runtime_shape_name": {
        "aggregatable": true,
        "count": 0,
        "esTypes": [
          "keyword"
        ],
        "format": {
          "id": "string"
        },
        "name": "runtime_shape_name",
        "readFromDocValues": false,
        "runtimeField": {
          "script": {
            "source": "emit(doc[\u0027shape_name\u0027].value)"
          },
          "type": "keyword"
        },
        "scripted": false,
        "searchable": true,
        "shortDotsEnable": false,
        "type": "string"
      }
    },
    "id": "b561acfb-0181-455e-84a3-ce8980b2272f",
    "name": "My Logstash data view",
    "namespaces": [
      "default"
    ],
    "runtimeFieldMap": {
      "runtime_shape_name": {
        "script": {
          "source": "emit(doc[\u0027shape_name\u0027].value)"
        },
        "type": "keyword"
      }
    },
    "sourceFilters": [],
    "title": "logstash-*",
    "typeMeta": {},
    "version": "WzQ5LDJd"
  }
}
```

#### A bad request response.

The request was rejected because the payload or query parameters are missing required fields or contain invalid values.

```json
{
  "error": "Bad Request",
  "message": "[request body.data_view.title]: expected value of type [string] but got [undefined]",
  "statusCode": 400
}
```

