---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
---
Simulate index template without new template in the body:
- requires:
    cluster_features:
    - "gte_v7.8.0"
    reason: "simulate index template API is only in 7.8.0+"
    test_runner_features:
    - "default_shards"
- do:
    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"
- do:
    indices.simulate_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:
    template.settings.index.number_of_shards: "1"
- match:
    template.settings.index.number_of_replicas: "0"
- match:
    template.mappings.properties.field.type: "keyword"
- match:
    overlapping: []
---
Simulate index template specifying a new template:
- requires:
    cluster_features:
    - "gte_v7.8.0"
    reason: "simulate index template API is only in 7.8.0+"
    test_runner_features:
    - "default_shards"
- do:
    indices.put_index_template:
      name: "existing_test"
      body:
        index_patterns: "test*"
        priority: 10
        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"
- do:
    cluster.put_component_template:
      name: "ct"
      body:
        template:
          settings:
            index.number_of_replicas: 2
          mappings:
            properties:
              ct_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"
- do:
    indices.simulate_index_template:
      name: "test"
      body:
        index_patterns: "test*"
        priority: 15
        template:
          settings:
            index.blocks.write: true
          aliases:
            test_alias: {}
        composed_of:
        - "ct"
    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:
    template.settings.index.blocks.write: "true"
- match:
    template.settings.index.number_of_replicas: "2"
- match:
    template.mappings.properties.ct_field.type: "keyword"
- match:
    overlapping.0.name: "existing_test"
- match:
    overlapping.0.index_patterns:
    - "test*"
- length:
    template.aliases: 1
- is_true: "template.aliases.test_alias"
---
Simulate index template with index not matching any template:
- requires:
    cluster_features:
    - "gte_v7.8.0"
    reason: "simulate index template API is only in 7.8.0+"
    test_runner_features: "allowed_warnings"
- 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*"
        priority: 10
        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"
- do:
    indices.simulate_index_template:
      name: "will_not_match"
    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:
    body: null
---
Simulate index matches overlapping legacy and composable templates:
- requires:
    cluster_features:
    - "gte_v7.8.0"
    reason: "simulate index template API is only in 7.8.0+"
    test_runner_features:
    - "allowed_warnings"
    - "default_shards"
- do:
    indices.put_template:
      name: "v1_template"
      body:
        index_patterns:
        - "test*"
        - "t1*"
        settings:
          number_of_shards: 5
    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:
    allowed_warnings:
    - "index template [v2_template] has index patterns [test*] matching patterns from\
      \ existing older templates [v1_template] with patterns (v1_template => [test*,\
      \ t1*]); this template [v2_template] will take precedence during new index creation"
    indices.put_index_template:
      name: "v2_template"
      body:
        index_patterns: "test*"
        priority: 10
        template:
          settings:
            number_of_shards: 10
            number_of_replicas: 2
          mappings:
            properties:
              field:
                type: "text"
    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:
    allowed_warnings:
    - "index template [winning_v2_template] has index patterns [test*] matching patterns\
      \ from existing older templates [v1_template] with patterns (v1_template =>\
      \ [test*, t1*]); this template [winning_v2_template] will take precedence during\
      \ new index creation"
    indices.put_index_template:
      name: "winning_v2_template"
      body:
        index_patterns: "test*"
        priority: 20
        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"
- do:
    indices.simulate_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:
    template.settings.index.number_of_shards: "1"
- match:
    template.settings.index.number_of_replicas: "0"
- match:
    template.mappings.properties.field.type: "keyword"
- match:
    overlapping.0.name: "v1_template"
- match:
    overlapping.0.index_patterns:
    - "test*"
    - "t1*"
- match:
    overlapping.1.name: "v2_template"
- match:
    overlapping.1.index_patterns:
    - "test*"
---
Simulate an index for and index or alias that already exists:
- requires:
    cluster_features:
    - "gte_v8.2.0"
    reason: "simulating index template API for an existing index has not yet been\
      \ backported"
    test_runner_features:
    - "default_shards"
- do:
    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"
- do:
    indices.create:
      index: "test_index"
      body:
        settings:
          index.number_of_shards: 2
        aliases:
          test_alias: {}
    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.simulate_index_template:
      name: "test_index"
    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:
    template.settings.index.number_of_shards: "1"
- match:
    template.settings.index.number_of_replicas: "0"
- match:
    template.mappings.properties.field.type: "keyword"
- match:
    overlapping: []
- do:
    indices.simulate_index_template:
      name: "test_alias"
    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:
    template.settings.index.number_of_shards: "1"
- match:
    template.settings.index.number_of_replicas: "0"
- match:
    template.mappings.properties.field.type: "keyword"
- match:
    overlapping: []
---
Simulate index template with lifecycle and include defaults:
- requires:
    cluster_features:
    - "gte_v8.11.0"
    reason: "Lifecycle is only available in 8.11+"
    test_runner_features:
    - "default_shards"
- do:
    indices.put_index_template:
      name: "test"
      body:
        index_patterns: "test*"
        template:
          lifecycle:
            data_retention: "7d"
        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.simulate_index_template:
      name: "test"
      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:
    template.lifecycle.enabled: true
- match:
    template.lifecycle.data_retention: "7d"
- is_true: "template.lifecycle.rollover"
- match:
    overlapping: []
