---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
---
Dynamic templates:
- requires:
    test_runner_features:
    - "contains"
    cluster_features:
    - "gte_v8.8.0"
    reason: "Exception type has changed in 8.8.0"
- do:
    indices.create:
      index: "test_index"
      body:
        settings:
          number_of_shards: 1
        mappings:
          dynamic_templates:
          - location:
              mapping:
                type: "geo_point"
          - my_location:
              match: "my*"
              mapping:
                type: "geo_point"
          - string:
              mapping:
                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:
    bulk:
      refresh: true
      body:
      - create:
          _index: "test_index"
          _id: "id_1"
          dynamic_templates:
            location: "location"
      - location: "41.12,-71.34"
      - index:
          _index: "test_index"
          _id: "id_2"
          dynamic_templates:
            location: "location"
      - location:
        - -71.34
        - 41.12
    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:
    errors: false
- match:
    items.0.create.result: "created"
- match:
    items.1.index.result: "created"
- do:
    search:
      index: "test_index"
      body:
        query:
          geo_bounding_box:
            location:
              top_left:
                lat: 42
                lon: -72
              bottom_right:
                lat: 40
                lon: -74
    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:
    hits.total.value: 2
- match:
    hits.hits.0._id: "id_1"
- match:
    hits.hits.1._id: "id_2"
- do:
    bulk:
      refresh: true
      body:
      - index:
          _index: "test_index"
          _id: "id_3"
      - my_location: "41.12,-71.34"
      - create:
          _index: "test_index"
          _id: "id_4"
          dynamic_templates:
            my_location: "my_location"
      - my_location: "41.12,-71.34"
    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:
    search:
      index: "test_index"
      body:
        query:
          geo_bounding_box:
            my_location:
              top_left:
                lat: 42
                lon: -72
              bottom_right:
                lat: 40
                lon: -74
    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:
    hits.total.value: 2
- match:
    hits.hits.0._id: "id_3"
- match:
    hits.hits.1._id: "id_4"
- do:
    bulk:
      refresh: true
      body:
      - index:
          _index: "test_index"
          _id: "id_5"
          dynamic_templates:
            location: "foo_bar"
      - location:
        - -71.34
        - 41.12
      - index:
          _index: "test_index"
          _id: "id_6"
          dynamic_templates:
            my_location: "foo_bar"
      - my_location: "41.12,-71.34"
      - index:
          _index: "test_index"
          _id: "id_7"
          dynamic_templates:
            location: "bar_foo"
      - location: "41.12,-71.34"
    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:
    errors: false
- match:
    items.0.index.result: "created"
- match:
    items.1.index.result: "created"
- match:
    items.2.index.result: "created"
- do:
    bulk:
      refresh: true
      body:
      - index:
          _index: "test_index"
          _id: "id_8"
          dynamic_templates:
            foo_location: "bar_foo"
      - foo_location:
        - -71.34
        - 41.12
      - index:
          _index: "test_index"
          _id: "id_9"
          dynamic_templates:
            foo_location: "foo_bar"
      - foo_location: "41.12,-71.34"
      - index:
          _index: "test_index"
          _id: "id_10"
          dynamic_templates:
            new_location: "foo"
      - location: "41.12,-71.34"
    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:
    errors: true
- match:
    items.0.index.status: 400
- match:
    items.0.index.error.type: "document_parsing_exception"
- contains:
    items.0.index.error.reason: "Can't find dynamic template for dynamic template\
      \ name [bar_foo] of field [foo_location]"
- match:
    items.1.index.status: 400
- match:
    items.1.index.error.type: "document_parsing_exception"
- contains:
    items.1.index.error.reason: "Can't find dynamic template for dynamic template\
      \ name [foo_bar] of field [foo_location]"
- match:
    items.2.index.status: 201
- match:
    items.2.index.result: "created"
- do:
    bulk:
      body:
      - index:
          _index: "test_index"
          _id: "id_11"
          dynamic_templates:
            foo: "string"
      - foo.bar: "hello world"
      - index:
          _index: "test_index"
          _id: "id_12"
          dynamic_templates:
            foo.bar: "string"
      - foo.bar: "hello world"
    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:
    errors: true
- match:
    items.0.index.status: 400
- match:
    items.0.index.error.type: "document_parsing_exception"
- contains:
    items.0.index.error.reason: "failed to parse field [foo] of type [keyword] in\
      \ document with id 'id_11'. Preview of field's value: '{bar=hello world}'"
- match:
    items.1.index.status: 201
- match:
    items.1.index.result: "created"
---
Dynamic templates with op_type:
- requires:
    cluster_features:
    - "gte_v8.6.1"
    reason: "bug fixed in 8.6.1"
- do:
    indices.create:
      index: "test_index"
      body:
        settings:
          number_of_shards: 1
        mappings:
          dynamic_templates:
          - location:
              mapping:
                type: "geo_point"
          - my_location:
              match: "my*"
              mapping:
                type: "geo_point"
          - string:
              mapping:
                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:
    bulk:
      refresh: true
      body:
      - index:
          _index: "test_index"
          _id: "id_1"
          op_type: "create"
          dynamic_templates:
            location: "location"
      - location: "41.12,-71.34"
      - index:
          _index: "test_index"
          _id: "id_2"
          op_type: "index"
          dynamic_templates:
            location: "location"
      - location:
        - -71.34
        - 41.12
    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:
    errors: false
- match:
    items.0.create.result: "created"
- match:
    items.1.index.result: "created"
- do:
    search:
      index: "test_index"
      body:
        query:
          geo_bounding_box:
            location:
              top_left:
                lat: 42
                lon: -72
              bottom_right:
                lat: 40
                lon: -74
    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:
    hits.total.value: 2
- match:
    hits.hits.0._id: "id_1"
- match:
    hits.hits.1._id: "id_2"
