Create a data view Generally available; added in 9.6.0

POST /api/data_views/v2

Spaces method and path for this operation:

post /s/{space_id}/api/data_views/v2

Refer to Spaces for more information.

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. Scripted fields are deprecated and can't be set through this API; sending scripted_fields fails with a 400.

[Required authorization] Route required privileges: indexPatterns:manage.

Headers

  • kbn-xsrf string Required

    A required header to protect against CSRF attacks

application/json

Body

  • allow_hidden_indices boolean

    When true, allows the data view to match hidden indices.

  • field_filters array[string]

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

    Not more than 10000 elements. Minimum length of each is 1, maximum length of each is 1000.

  • field_settings object

    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 Required

    The index pattern (Elasticsearch index expression) to use as the data source. Example: "my-index-*".

    Minimum length is 1.

  • name string

    The name of the data view. Example: "Sample data view".

    Minimum length is 1, maximum length is 256.

  • time_field string

    The name of the time field in the index. Used for time-based filtering. Example: "@timestamp".

Responses

  • 201 application/json

    The data view was created.

    Hide response attributes Show response attributes object
    • data object Required

      The data view definition.

      Additional properties are NOT allowed.

      Hide data attributes Show data attributes object
      • allow_hidden_indices boolean

        When true, allows the data view to match hidden indices.

      • field_filters array[string]

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

        Not more than 10000 elements. Minimum length of each is 1, maximum length of each is 1000.

      • field_settings object

        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

        Kibana provides a unique identifier for each data view, or you can create your own.

        Minimum length is 1, maximum length is 256.

      • index_pattern string Required

        The index pattern (Elasticsearch index expression) to use as the data source. Example: "my-index-*".

        Minimum length is 1.

      • name string

        The name of the data view. Example: "Sample data view".

        Minimum length is 1, maximum length is 256.

      • scripted_fields object Deprecated

        Deprecated scripted fields, keyed by field name. This property is read-only: it is only returned in responses, and sending it in a create or update request fails with a 400.

        Hide scripted_fields attribute Show scripted_fields attribute object Deprecated
        • * object Additional properties

          A deprecated scripted field. Scripted fields are evaluated at query time by Elasticsearch and are read-only in this API.

          Additional properties are NOT allowed.

          Hide * attributes Show * attributes object
          • custom_description string

            Add a description to the field. It's displayed next to the field on the Discover, Lens, and Data View Management pages.

            Minimum length is 1.

          • custom_label string

            Create a label to display in place of the field name in Discover, Maps, Lens, Visualize, and TSVB. Useful for shortening a long field name. Queries and filters use the original field name.

            Minimum length is 1.

          • format object

            Set your preferred format for displaying the value. Changing the format can affect the value and prevent highlighting in Discover.

            Any of:
          • lang string

            The language of the script. Example: "painless".

            Minimum length is 1, maximum length is 1000.

          • popularity number

            Adjust the popularity to make the field appear higher or lower in the fields list. By default, Discover orders fields from most selected to least selected.

            Minimum value is 0.

          • script string Required

            The script that computes the value of the scripted field. Scripted fields are deprecated; use runtime fields instead.

            Minimum length is 1.

          • type string Required

            The Kibana field type of the scripted field (e.g., "string", "number", "date", "boolean", "ip", "geo_point").

            Minimum length is 1, maximum length is 1000.

      • time_field string

        The name of the time field in the index. Used for time-based filtering. Example: "@timestamp".

    • id string Required

      The ID of the data view.

      Maximum length is 1000.

    • meta object Required

      Metadata about the data view.

      Additional properties are NOT allowed.

      Hide meta attributes Show meta attributes object
      • 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 array[string]

        The IDs of the spaces where the data view is available.

        Not more than 100 elements. Maximum length of each is 1000.

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

POST /api/data_views/v2
curl \
 --request POST 'https://localhost:5601/api/data_views/v2' \
 --header "Authorization: $API_KEY" \
 --header "Content-Type: application/json" \
 --header "kbn-xsrf: true" \
 --data '{
  "index_pattern": "logs-*",
  "name": "Web logs",
  "time_field": "@timestamp"
}'
Request example
{
  "index_pattern": "logs-*",
  "name": "Web logs",
  "time_field": "@timestamp"
}
Response examples (201)
{
  "data": {
    "index_pattern": "logs-*",
    "name": "Web logs",
    "time_field": "@timestamp"
  },
  "id": "c0ffee00-d57a-11ef-9a52-4f3c2a8d0e1b",
  "meta": {
    "managed": false,
    "spaces": [
      "default"
    ],
    "version": "WzEsMV0="
  }
}