---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    cluster_features:
    - "gte_v8.5.1"
    reason: "fixed in 8.5.1"
- do:
    indices.create:
      index: "dates_year_only"
      body:
        mappings:
          properties:
            date:
              type: "date"
              format: "uuuu"
    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\" : \"dates_year_only\", \"_id\" : \"1\" } }"
      - "{\"date\" : \"1900\", \"field\" : 1 }"
      - "{ \"index\" : { \"_index\" : \"dates_year_only\", \"_id\" : \"2\" } }"
      - "{\"date\" : \"2022\", \"field\" : 2 }"
      - "{ \"index\" : { \"_index\" : \"dates_year_only\", \"_id\" : \"3\" } }"
      - "{\"date\" : \"2022\", \"field\" : 3 }"
      - "{ \"index\" : { \"_index\" : \"dates_year_only\", \"_id\" : \"4\" } }"
      - "{\"date\" : \"1500\", \"field\" : 4 }"
    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: "dates"
      body:
        mappings:
          properties:
            date:
              type: "date"
    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\" : \"dates\", \"_id\" : \"1\" } }"
      - "{\"date\" : \"1900-01-01T12:12:12.123456789Z\", \"field\" : 1 }"
      - "{ \"index\" : { \"_index\" : \"dates\", \"_id\" : \"2\" } }"
      - "{\"date\" : \"2022-01-01T12:12:12.123456789Z\", \"field\" : 2 }"
      - "{ \"index\" : { \"_index\" : \"dates\", \"_id\" : \"3\" } }"
      - "{\"date\" : \"2022-01-03T12:12:12.123456789Z\", \"field\" : 3 }"
      - "{ \"index\" : { \"_index\" : \"dates\", \"_id\" : \"4\" } }"
      - "{\"date\" : \"1500-01-01T12:12:12.123456789Z\", \"field\" : 4 }"
      - "{ \"index\" : { \"_index\" : \"dates\", \"_id\" : \"5\" } }"
      - "{\"date\" : \"1500-01-05T12:12:12.123456789Z\", \"field\" : 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"
---
test range query for all docs with year uuuu:
- do:
    search:
      rest_total_hits_as_int: true
      index: "dates"
      body:
        sort: "field"
        query:
          range:
            date:
              gte: 1000
              lte: 2023
              format: "uuuu"
    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: 5
- length:
    hits.hits: 5
---
test match query gte and lt for single result with year uuuu:
- do:
    search:
      rest_total_hits_as_int: true
      index: "dates"
      body:
        sort: "field"
        query:
          range:
            date:
              gte: 1500
              lte: 1500
              format: "uuuu"
    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: 1
- length:
    hits.hits: 1
- match:
    hits.hits.0._id: "4"
---
test match query gte and lte with year uuuu:
- do:
    search:
      rest_total_hits_as_int: true
      index: "dates"
      body:
        sort: "field"
        query:
          range:
            date:
              gte: 1500
              lte: 2000
              format: "uuuu"
    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: 3
- length:
    hits.hits: 3
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.1._id: "4"
- match:
    hits.hits.2._id: "5"
---
test match query with year uuuu:
- do:
    search:
      rest_total_hits_as_int: true
      index: "dates_year_only"
      body:
        sort: "field"
        query:
          match:
            date:
              query: "1500"
    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: 1
- length:
    hits.hits: 1
- match:
    hits.hits.0._id: "4"
---
from, to, include_lower, include_upper deprecated:
- skip:
    awaits_fix: "deprecated parameters are removed in 9.0"
- requires:
    cluster_features: "gte_v8.16.0"
    reason: "from, to, include_lower, include_upper parameters are deprecated since\
      \ 8.16.0"
    test_runner_features: "warnings"
- do:
    warnings:
    - "Deprecated field [from] used, this field is unused and will be removed entirely"
    - "Deprecated field [to] used, this field is unused and will be removed entirely"
    - "Deprecated field [include_lower] used, this field is unused and will be removed\
      \ entirely"
    - "Deprecated field [include_upper] used, this field is unused and will be removed\
      \ entirely"
    search:
      index: "dates"
      body:
        sort: "field"
        query:
          range:
            date:
              from: 1000
              to: 2023
              include_lower: false
              include_upper: false
    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"
---
test bad dates in range - past:
- requires:
    cluster_features:
    - "mapper.range.invalid_date_fix"
    reason: "Fix for invalid date required"
- do:
    catch: "/illegal_argument_exception/"
    search:
      index: "dates"
      body:
        sort: "field"
        query:
          range:
            date:
              gte: -522000000
              lte: 2023
              format: "date_optional_time"
    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"
---
test bad dates in range - future:
- requires:
    cluster_features:
    - "mapper.range.invalid_date_fix"
    reason: "Fix for invalid date required"
- do:
    catch: "/illegal_argument_exception/"
    search:
      index: "dates"
      body:
        sort: "field"
        query:
          range:
            date:
              gte: 2020
              lte: 522000000
              format: "date_optional_time"
    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"
