Path parameters

  • namestring Required

    The name of the template

Query parameters

  • createboolean

    If true, this request cannot replace or update existing index templates.

  • master_timeoutstring

    Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error.

    Values are -1 or 0.

  • ordernumber

    Order in which Elasticsearch applies this template if index matches multiple templates.

    Templates with lower 'order' values are merged first. Templates with higher 'order' values are merged later, overriding templates with lower values.

  • causestring

    User defined reason for creating/updating the index template

application/json

BodyRequired

  • aliasesobject

    Aliases for the index.

    Hide aliases attribute Show aliases attribute object
    • *object Additional properties
      Hide * attributes Show * attributes object
      • filterobject

        An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.

        External documentation
      • index_routingstring
      • is_hiddenboolean

        If true, the alias is hidden. All indices for the alias must have the same is_hidden value.

      • is_write_indexboolean

        If true, the index is the write index for the alias.

      • routingstring
      • search_routingstring
  • index_patternsstring | array[string]

    Array of wildcard expressions used to match the names of indices during creation.

  • mappingsobject
    Hide mappings attributes Show mappings attributes object
    • all_fieldobject
      Hide all_field attributes Show all_field attributes object
      • analyzerstring Required
      • enabledboolean Required
      • omit_normsboolean Required
      • search_analyzerstring Required
      • similaritystring Required
      • storeboolean Required
      • store_term_vector_offsetsboolean Required
      • store_term_vector_payloadsboolean Required
      • store_term_vector_positionsboolean Required
      • store_term_vectorsboolean Required
    • date_detectionboolean
    • dynamicstring

      Values are strict, runtime, true, or false.

    • dynamic_date_formatsarray[string]
    • dynamic_templatesarray[object]
    • _field_namesobject
      Hide _field_names attribute Show _field_names attribute object
      • enabledboolean Required
    • index_fieldobject
      Hide index_field attribute Show index_field attribute object
      • enabledboolean Required
    • _metaobject
      Hide _meta attribute Show _meta attribute object
      • *object Additional properties
    • numeric_detectionboolean
    • propertiesobject
    • _routingobject
      Hide _routing attribute Show _routing attribute object
      • requiredboolean Required
    • _sizeobject
      Hide _size attribute Show _size attribute object
      • enabledboolean Required
    • _sourceobject
      Hide _source attributes Show _source attributes object
      • compressboolean
      • compress_thresholdstring
      • enabledboolean
      • excludesarray[string]
      • includesarray[string]
      • modestring

        Values are disabled, stored, or synthetic.

    • runtimeobject
      Hide runtime attribute Show runtime attribute object
      • *object Additional properties
        Hide * attributes Show * attributes object
        • fieldsobject

          For type composite

          Hide fields attribute Show fields attribute object
          • *object Additional properties
            Hide * attribute Show * attribute object
            • typestring Required

              Values are boolean, composite, date, double, geo_point, geo_shape, ip, keyword, long, or lookup.

        • fetch_fieldsarray[object]

          For type lookup

          Hide fetch_fields attributes Show fetch_fields attributes object
          • fieldstring Required

            Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.

          • formatstring
        • formatstring

          A custom format for date type runtime fields.

        • input_fieldstring

          Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.

        • target_fieldstring

          Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.

        • target_indexstring
        • scriptobject
          Hide script attributes Show script attributes object
          • sourcestring | object

            One of:
          • idstring
          • paramsobject

            Specifies any named parameters that are passed into the script as variables. Use parameters instead of hard-coded values to decrease compile time.

            Hide params attribute Show params attribute object
            • *object Additional properties
          • langstring

            Any of:

            Values are painless, expression, mustache, or java.

          • optionsobject
            Hide options attribute Show options attribute object
            • *string Additional properties
        • typestring Required

          Values are boolean, composite, date, double, geo_point, geo_shape, ip, keyword, long, or lookup.

    • enabledboolean
    • subobjectsstring

      Values are true or false.

    • _data_stream_timestampobject
      Hide _data_stream_timestamp attribute Show _data_stream_timestamp attribute object
      • enabledboolean Required
  • ordernumber

    Order in which Elasticsearch applies this template if index matches multiple templates.

    Templates with lower 'order' values are merged first. Templates with higher 'order' values are merged later, overriding templates with lower values.

  • settingsobject
    Index settings
  • versionnumber

Responses

  • 200 application/json
    Hide response attribute Show response attribute object
    • acknowledgedboolean Required

      For a successful response, this value is always true. On failure, an exception is returned instead.

POST /_template/{name}
curl \
 --request POST 'http://api.example.com/_template/{name}' \
 --header "Authorization: $API_KEY" \
 --header "Content-Type: application/json" \
 --data '"{\n  \"index_patterns\": [\n    \"te*\",\n    \"bar*\"\n  ],\n  \"settings\": {\n    \"number_of_shards\": 1\n  },\n  \"mappings\": {\n    \"_source\": {\n      \"enabled\": false\n    }\n  },\n  \"properties\": {\n    \"host_name\": {\n      \"type\": \"keyword\"\n    },\n    \"created_at\": {\n      \"type\": \"date\",\n      \"format\": \"EEE MMM dd HH:mm:ss Z yyyy\"\n    }\n  }\n}"'
{
  "index_patterns": [
    "te*",
    "bar*"
  ],
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "_source": {
      "enabled": false
    }
  },
  "properties": {
    "host_name": {
      "type": "keyword"
    },
    "created_at": {
      "type": "date",
      "format": "EEE MMM dd HH:mm:ss Z yyyy"
    }
  }
}
You can include index aliases in an index template. During index creation, the `{index}` placeholder in the alias name will be replaced with the actual index name that the template gets applied to.
{
  "index_patterns": [
    "te*"
  ],
  "settings": {
    "number_of_shards": 1
  },
  "aliases": {
    "alias1": {},
    "alias2": {
      "filter": {
        "term": {
          "user.id": "kimchy"
        }
      },
      "routing": "shard-1"
    },
    "{index}-alias": {}
  }
}