---
setup:
- skip:
    cluster_features:
    - "gte_v7.8.0"
    reason: "index template v2 API unavailable before 7.8"
    features:
    - "allowed_warnings"
    - "headers"
    - "allowed_warnings_regex"
- do:
    allowed_warnings:
    - "index template [test] has index patterns [test-*] matching patterns from existing\
      \ older templates [global] with patterns (global => [*]); this template [test]\
      \ will take precedence during new index creation"
    indices.put_index_template:
      name: "test"
      body:
        index_patterns: "test-*"
        template:
          settings:
            number_of_shards: 1
            number_of_replicas: 0
          mappings:
            properties:
              field:
                type: "keyword"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
---
Get index template:
- do:
    indices.get_index_template:
      name: "test"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    index_templates.0.name: "test"
- match:
    index_templates.0.index_template.index_patterns:
    - "test-*"
- match:
    index_templates.0.index_template.template.settings:
      index:
        number_of_shards: "1"
        number_of_replicas: "0"
- match:
    index_templates.0.index_template.template.mappings:
      properties:
        field:
          type: "keyword"
---
Get all index templates:
- do:
    allowed_warnings:
    - "index template [test2] has index patterns [test2-*] matching patterns from\
      \ existing older templates [global] with patterns (global => [*]); this template\
      \ [test2] will take precedence during new index creation"
    indices.put_index_template:
      name: "test2"
      body:
        index_patterns: "test2-*"
        template:
          settings:
            number_of_shards: 1
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.get_index_template: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- is_true: "index_templates.0.name"
- is_true: "index_templates.1.name"
---
Pattern matching in index templates:
- do:
    allowed_warnings:
    - "index template [test2] has index patterns [test2-*] matching patterns from\
      \ existing older templates [global] with patterns (global => [*]); this template\
      \ [test2] will take precedence during new index creation"
    indices.put_index_template:
      name: "test2"
      body:
        index_patterns: "test2-*"
        template:
          settings:
            number_of_shards: 1
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.get_index_template:
      name: "*"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- is_true: "index_templates.0.name"
- is_true: "index_templates.1.name"
- do:
    indices.get_index_template:
      name: "test*"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    index_templates.0.name: "/test.*/"
- match:
    index_templates.1.name: "/test.*/"
---
Get index template with local flag:
- do:
    indices.get_index_template:
      name: "test"
      local: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    index_templates.0.name: "test"
---
Add data stream lifecycle:
- skip:
    cluster_features:
    - "gte_v8.11.0"
    reason: "Data stream lifecycle in index templates was updated after 8.10"
    features: "allowed_warnings"
- do:
    allowed_warnings:
    - "index template [test-lifecycle] has index patterns [data-stream-with-lifecycle-*]\
      \ matching patterns from existing older templates [global] with patterns (global\
      \ => [*]); this template [test-lifecycle] will take precedence during new index\
      \ creation"
    indices.put_index_template:
      name: "test-lifecycle"
      body:
        index_patterns: "data-stream-with-lifecycle-*"
        template:
          settings:
            number_of_shards: 1
          mappings:
            properties:
              field:
                type: "keyword"
          lifecycle:
            data_retention: "30d"
        data_stream: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.get_index_template:
      name: "test-lifecycle"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    index_templates.0.name: "test-lifecycle"
- match:
    index_templates.0.index_template.index_patterns:
    - "data-stream-with-lifecycle-*"
- match:
    index_templates.0.index_template.template.settings:
      index:
        number_of_shards: "1"
- match:
    index_templates.0.index_template.template.mappings:
      properties:
        field:
          type: "keyword"
- match:
    index_templates.0.index_template.template.lifecycle.enabled: true
- match:
    index_templates.0.index_template.template.lifecycle.data_retention: "30d"
---
Get data stream lifecycle with default rollover:
- skip:
    cluster_features:
    - "gte_v8.11.0"
    reason: "Data stream lifecycle in index templates was updated after 8.10"
    features: "allowed_warnings"
- do:
    allowed_warnings:
    - "index template [test-lifecycle] has index patterns [data-stream-with-lifecycle-*]\
      \ matching patterns from existing older templates [global] with patterns (global\
      \ => [*]); this template [test-lifecycle] will take precedence during new index\
      \ creation"
    indices.put_index_template:
      name: "test-lifecycle"
      body:
        index_patterns: "data-stream-with-lifecycle-*"
        template:
          lifecycle:
            data_retention: "30d"
        data_stream: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.get_index_template:
      name: "test-lifecycle"
      include_defaults: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    index_templates.0.name: "test-lifecycle"
- match:
    index_templates.0.index_template.index_patterns:
    - "data-stream-with-lifecycle-*"
- match:
    index_templates.0.index_template.template.lifecycle.enabled: true
- match:
    index_templates.0.index_template.template.lifecycle.data_retention: "30d"
- is_true: "index_templates.0.index_template.template.lifecycle.rollover"
---
Reject data stream lifecycle without data stream configuration:
- requires:
    cluster_features:
    - "gte_v8.11.0"
    reason: "Data stream lifecycle in index templates was updated after 8.10"
- do:
    catch: "bad_request"
    indices.put_index_template:
      name: "invalid-test-lifecycle"
      body:
        index_patterns: "index-with-lifecycle-*"
        template:
          settings:
            number_of_shards: 1
          mappings:
            properties:
              field:
                type: "keyword"
          lifecycle:
            data_retention: "30d"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
---
Get index template always shows composed_of:
- requires:
    cluster_features:
    - "gte_v8.13.0"
    reason: "A bug was fixed in 8.13.0 to make `composed_of` always returned"
- do:
    indices.get_index_template:
      name: "test"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    index_templates.0.name: "test"
- match:
    index_templates.0.index_template.composed_of: []
