---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
---
Format sort values for missing dates:
- requires:
    cluster_features:
    - "search.sort.date_format_missing_as_null"
    reason: "missing values as null requires search.sort.date_format_missing_as_null"
- do:
    indices.create:
      index: "test_missing_dates"
      body:
        mappings:
          properties:
            timestamp:
              type: "date"
              format: "yyyy-MM-dd HH:mm:ss.SSS"
            name:
              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
      index: "test_missing_dates"
      body: "{\"index\":{\"_id\": \"1\"}}\n{\"timestamp\":\"2021-10-13 00:30:04.828\"\
        , \"name\": \"with_date_1\"}\n{\"index\":{\"_id\": \"2\"}}\n{\"name\": \"\
        missing_date\"}\n{\"index\":{\"_id\": \"3\"}}\n{\"timestamp\":\"2021-06-11\
        \ 04:30:04.828\", \"name\": \"with_date_2\"}\n"
    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_missing_dates"
      body:
        size: 3
        sort:
        - timestamp:
            order: "asc"
            format: "strict_date_optional_time_nanos"
            missing: "_last"
    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: 3
- length:
    hits.hits: 3
- match:
    hits.hits.0._id: "3"
- match:
    hits.hits.0.sort:
    - "2021-06-11T04:30:04.828Z"
- match:
    hits.hits.1._id: "1"
- match:
    hits.hits.1.sort:
    - "2021-10-13T00:30:04.828Z"
- match:
    hits.hits.2._id: "2"
- match:
    hits.hits.2.sort:
    - null
- do:
    search:
      index: "test_missing_dates"
      body:
        size: 3
        sort:
        - timestamp:
            order: "desc"
            format: "strict_date_optional_time_nanos"
            missing: "_last"
    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: 3
- length:
    hits.hits: 3
- match:
    hits.hits.0._id: "1"
- match:
    hits.hits.0.sort:
    - "2021-10-13T00:30:04.828Z"
- match:
    hits.hits.1._id: "3"
- match:
    hits.hits.1.sort:
    - "2021-06-11T04:30:04.828Z"
- match:
    hits.hits.2._id: "2"
- match:
    hits.hits.2.sort:
    - null
- do:
    search:
      index: "test_missing_dates"
      body:
        size: 3
        sort:
        - timestamp:
            order: "asc"
            format: "strict_date_optional_time_nanos"
            missing: "_first"
    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: 3
- length:
    hits.hits: 3
- match:
    hits.hits.0._id: "2"
- match:
    hits.hits.0.sort:
    - null
- match:
    hits.hits.1._id: "3"
- match:
    hits.hits.1.sort:
    - "2021-06-11T04:30:04.828Z"
- match:
    hits.hits.2._id: "1"
- match:
    hits.hits.2.sort:
    - "2021-10-13T00:30:04.828Z"
- do:
    search:
      index: "test_missing_dates"
      body:
        size: 3
        sort:
        - timestamp:
            order: "asc"
            format: "epoch_millis"
            missing: "_last"
    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: 3
- length:
    hits.hits: 3
- match:
    hits.hits.0._id: "3"
- match:
    hits.hits.0.sort:
    - "1623385804828"
- match:
    hits.hits.1._id: "1"
- match:
    hits.hits.1.sort:
    - "1634085004828"
- match:
    hits.hits.2._id: "2"
- match:
    hits.hits.2.sort:
    - null
---
Format sort values for missing date_nanos:
- requires:
    cluster_features:
    - "search.sort.date_format_missing_as_null"
    reason: "missing values as null requires search.sort.date_format_missing_as_null"
- do:
    indices.create:
      index: "test_missing_date_nanos"
      body:
        mappings:
          properties:
            timestamp:
              type: "date_nanos"
              format: "yyyy-MM-dd HH:mm:ss.SSSSSS"
            name:
              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
      index: "test_missing_date_nanos"
      body: "{\"index\":{\"_id\": \"1\"}}\n{\"timestamp\":\"2021-10-13 00:30:04.828123\"\
        , \"name\": \"with_date_1\"}\n{\"index\":{\"_id\": \"2\"}}\n{\"name\": \"\
        missing_date\"}\n{\"index\":{\"_id\": \"3\"}}\n{\"timestamp\":\"2021-06-11\
        \ 04:30:04.828456\", \"name\": \"with_date_2\"}\n"
    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_missing_date_nanos"
      body:
        size: 3
        sort:
        - timestamp:
            order: "asc"
            format: "strict_date_optional_time_nanos"
            missing: "_last"
    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: 3
- length:
    hits.hits: 3
- match:
    hits.hits.0._id: "3"
- match:
    hits.hits.0.sort:
    - "2021-06-11T04:30:04.828456Z"
- match:
    hits.hits.1._id: "1"
- match:
    hits.hits.1.sort:
    - "2021-10-13T00:30:04.828123Z"
- match:
    hits.hits.2._id: "2"
- match:
    hits.hits.2.sort:
    - null
- do:
    search:
      index: "test_missing_date_nanos"
      body:
        size: 3
        sort:
        - timestamp:
            order: "desc"
            format: "strict_date_optional_time_nanos"
            missing: "_first"
    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: 3
- length:
    hits.hits: 3
- match:
    hits.hits.0._id: "2"
- match:
    hits.hits.0.sort:
    - null
- match:
    hits.hits.1._id: "1"
- match:
    hits.hits.1.sort:
    - "2021-10-13T00:30:04.828123Z"
- match:
    hits.hits.2._id: "3"
- match:
    hits.hits.2.sort:
    - "2021-06-11T04:30:04.828456Z"
