---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
---
Help:
- requires:
    cluster_features:
    - "gte_v7.8.0"
    reason: "format changed in 7.8 to accomodate V2 index templates"
- do:
    cat.templates:
      help: true
    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: "/^  name             .+   \\n\n    index_patterns   .+   \\n\n    order\
      \            .+   \\n\n    version          .+   \\n\n    composed_of      .+\
      \   \\n\n$/\n"
---
No templates:
- skip:
    features: "default_shards, no_xpack"
- do:
    cat.templates: {}
    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: "/^\n$/\n"
---
Normal templates:
- requires:
    cluster_features:
    - "gte_v7.8.0"
    reason: "format changed in 7.8 to accomodate V2 index templates"
- do:
    indices.put_template:
      name: "test"
      body:
        order: 0
        version: 1
        index_patterns: "test-*"
        settings:
          number_of_shards: 1
          number_of_replicas: 0
    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.put_template:
      name: "test_2"
      body:
        order: 1
        version: 2
        index_patterns: "test-2*"
        settings:
          number_of_shards: 1
          number_of_replicas: 0
    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:
    cat.templates: {}
    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: "/\n  (^|\\n)test     \\s+\n  \\[test-\\*\\]    \\s+\n  0             \
      \ \\s+\n  1              \\s+\n  (\\n|$)\n/\n"
- match:
    $body: "/\n (^|\\n)test_2    \\s+\n \\[test-2\\*\\]    \\s+\n 1              \
      \ \\s+\n 2               \\s+\n (\\n|$)\n/\n"
---
Filtered templates:
- requires:
    cluster_features:
    - "gte_v7.8.0"
    reason: "format changed in 7.8 to accomodate V2 index templates"
- do:
    indices.put_template:
      name: "test"
      body:
        order: 0
        version: 1
        index_patterns: "test*"
        settings:
          number_of_shards: 1
          number_of_replicas: 0
    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.put_template:
      name: "nomatch"
      body:
        order: 2
        version: 1
        index_patterns: "nomatch*"
        settings:
          number_of_shards: 1
          number_of_replicas: 0
    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:
    cat.templates:
      name: "test*"
    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: "/^\n    test    \\s+\n    \\[test\\*\\] \\s+\n    0       \\s+\n    1\
      \       \\s*\n    \\n\n$/\n"
---
Column headers:
- requires:
    cluster_features:
    - "gte_v7.8.0"
    reason: "format changed in 7.8 to accomodate V2 index templates"
- do:
    indices.put_template:
      name: "test"
      body:
        order: 0
        version: 1
        index_patterns: "test*"
        settings:
          number_of_shards: 1
          number_of_replicas: 0
    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:
    cat.templates:
      v: true
      name: "test"
    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: "/^\n   name            \\s+\n   index_patterns  \\s+\n   order       \
      \    \\s+\n   version         \\s+\n   composed_of\n   \\n\n   test        \
      \    \\s+\n   \\[test\\*\\]         \\s+\n   0               \\s+\n   1    \
      \           \\s*\n   \\n\n$/\n"
---
Select columns:
- requires:
    cluster_features:
    - "gte_v7.8.0"
    reason: "format changed in 7.8 to accomodate V2 index templates"
- do:
    indices.put_template:
      name: "test"
      body:
        order: 0
        version: 1
        index_patterns: "test*"
        settings:
          number_of_shards: 1
          number_of_replicas: 0
    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:
    cat.templates:
      h:
      - "name"
      - "index_patterns"
      v: true
      name: "test*"
    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: "/^\n    name        \\s+\n    index_patterns\n    \\n\n    test      \
      \  \\s+\n    \\[test*\\*\\]\n    \\n\n$/\n"
---
Sort templates:
- requires:
    cluster_features:
    - "gte_v7.8.0"
    reason: "format changed in 7.8 to accomodate V2 index templates"
    test_runner_features: "default_shards, no_xpack"
- do:
    indices.put_template:
      name: "test"
      body:
        order: 0
        index_patterns: "test*"
        settings:
          number_of_shards: 1
          number_of_replicas: 0
    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.put_template:
      name: "test_1"
      body:
        order: 0
        version: 1
        index_patterns: "test-*"
        settings:
          number_of_shards: 1
          number_of_replicas: 0
    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:
    cat.templates:
      h:
      - "name"
      - "index_patterns"
      - "version"
      s:
      - "version"
    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: "/^\n    test   \\s+ \\[test\\*\\]  \\s+   \\n \\n\n    test_1 \\s+ \\\
      [test-\\*\\] \\s+ 1 \\n \\n\n$/\n"
- do:
    cat.templates:
      h:
      - "name"
      - "index_patterns"
      - "version"
      s:
      - "version:desc"
    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: "/^\n    test_1 \\s+ \\[test-\\*\\]   \\s+ 1\\n \\n\n    test   \\s+ \\\
      [test\\*\\]    \\s+  \\n \\n\n\n$/\n"
---
Multiple template:
- requires:
    cluster_features:
    - "gte_v7.8.0"
    reason: "format changed in 7.8 to accomodate V2 index templates"
    test_runner_features: "default_shards, no_xpack"
- do:
    indices.put_template:
      name: "test_1"
      body:
        order: 0
        version: 1
        index_patterns:
        - "test*"
        - "test-*"
        settings:
          number_of_shards: 1
          number_of_replicas: 0
    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:
    cat.templates:
      h:
      - "name"
      - "index_patterns"
      v: true
    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: "/^\n   name         \\s+\n   index_patterns\n   \\n\n   test_1       \\\
      s+\n   \\[test\\*,\\ test-\\*\\]\n   \\n\n   \\n\n$/\n"
---
Mixture of legacy and composable templates:
- requires:
    cluster_features:
    - "gte_v7.8.0"
    reason: "format changed in 7.8 to accomodate V2 index templates"
    test_runner_features: "allowed_warnings"
- do:
    cluster.put_component_template:
      name: "foo"
      body:
        template:
          settings:
            number_of_shards: 1
            number_of_replicas: 0
    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.put_template:
      name: "test"
      body:
        order: 0
        version: 1
        index_patterns: "test-*"
        settings:
          number_of_shards: 1
          number_of_replicas: 0
    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 [testv2] has index patterns [v2-test] matching patterns from\
      \ existing older templates [global] with patterns (global => [*]); this template\
      \ [testv2] will take precedence during new index creation"
    indices.put_index_template:
      name: "testv2"
      body:
        index_patterns:
        - "v2-test"
        priority: 4
        version: 3
        composed_of:
        - "foo"
    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:
    cat.templates: {}
    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: "/\n  (^|\\n)test     \\s+\n  \\[test-\\*\\]    \\s+\n  0             \
      \ \\s+\n  1              \\s+\n  (\\n|$)\n/\n"
- match:
    $body: "/\n (^|\\n)testv2    \\s+\n \\[v2-test\\]     \\s+\n 4               \\\
      s+\n 3               \\s+\n \\[foo\\]\n/\n"
