---
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/v8/operation/operation-createdataviewdefaultw
resource: https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/kibana/v8/operation/operation-createdataviewdefaultw
products:
  - Kibana
---

# Create a data view

Authentication: required

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

## Paths

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

#### 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.

## Header parameters

- `kbn-xsrf` (string) — required
  Cross-site request forgery protection

## 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.
  - `fieldAttrs` (map string to object) — optional
    Map values (object)
    - `count` (integer) — optional
      Popularity count for the field.
    - `customDescription` (string · max length: 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` (string[]) — optional
    An array of space identifiers for sharing the data view between multiple spaces.
  - `runtimeFieldMap` (map string to object) — optional
    Map values (object)
    - `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` (object) — 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.
  - `fieldAttrs` (map string to object)
    Map values (object)
    - `count` (integer)
      Popularity count for the field.
    - `customDescription` (string · max length: 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` (string[])
    An array of space identifiers for sharing the data view between multiple spaces.
  - `runtimeFieldMap` (map string to object)
    Map values (object)
    - `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` (object) — 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": {
    "name": "My Logstash data view",
    "runtimeFieldMap": {
      "runtime_shape_name": {
        "script": {
          "source": "emit(doc[\u0027shape_name\u0027].value)"
        },
        "type": "keyword"
      }
    },
    "title": "logstash-*"
  }
}
```

#### curl

```curl
curl -X POST "${KIBANA_URL}/api/data_views/data_view" \
  -H "kbn-xsrf: true" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "data_view": {
      "name": "My Logstash data view",
      "runtimeFieldMap": {
        "runtime_shape_name": {
          "script": {
            "source": "emit(doc[\u0027shape_name\u0027].value)"
          },
          "type": "keyword"
        }
      },
      "title": "logstash-*"
    }
  }'
```

## Response examples

#### 200

`application/json`

Generated from the API spec. Values are representative. Unions use the first variant; deeply nested or large bodies may omit fields.

```json
{
  "data_view": {
    "allowNoIndex": false,
    "fieldAttrs": {
      "key": {
        "count": 0,
        "customDescription": "string",
        "customLabel": "string"
      }
    },
    "fieldFormats": {},
    "fields": {},
    "id": "ff959d40-b880-11e8-a6d9-e546fe2bba5f",
    "name": "string",
    "namespaces": [
      "default"
    ],
    "runtimeFieldMap": {
      "key": {
        "script": {
          "source": "string"
        },
        "type": "string"
      }
    },
    "sourceFilters": [
      {
        "value": "string"
      }
    ],
    "timeFieldName": "string",
    "title": "string",
    "typeMeta": {
      "aggs": {},
      "params": {}
    },
    "version": "WzQ2LDJd"
  }
}
```

#### 400

`application/json`

Generated from the API spec. Values are representative. Unions use the first variant; deeply nested or large bodies may omit fields.

```json
{
  "error": "Bad Request",
  "message": "string",
  "statusCode": 400
}
```

