---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    cluster_features:
    - "gte_v7.2.0"
    reason: "Implemented in 7.2"
- do:
    indices.create:
      index: "index1"
      body:
        mappings:
          properties:
            my_date:
              type: "date"
            my_date_nanos:
              type: "date_nanos"
            my_geo:
              type: "geo_point"
    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\" : \"index1\", \"_id\" : \"1\" } }"
      - "{ \"my_date\": \"2018-02-01T10:00:00Z\", \"my_date_nanos\": \"2018-02-01T00:00:00.223456789Z\"\
        , \"my_geo\": [-71.34, 41.13] }"
      - "{ \"index\" : { \"_index\" : \"index1\", \"_id\" : \"2\" } }"
      - "{ \"my_date\": \"2018-02-01T11:00:00Z\", \"my_date_nanos\": \"2018-02-01T00:00:00.123456789Z\"\
        , \"my_geo\": [-71.34, 41.14] }"
      - "{ \"index\" : { \"_index\" : \"index1\", \"_id\" : \"3\" } }"
      - "{ \"my_date\": \"2018-02-01T09:00:00Z\", \"my_date_nanos\": \"2018-02-01T00:00:00.323456789Z\"\
        , \"my_geo\": [-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"
---
test distance_feature query on date type:
- do:
    search:
      rest_total_hits_as_int: true
      index: "index1"
      body:
        query:
          distance_feature:
            field: "my_date"
            pivot: "1h"
            origin: "2018-02-01T08:00:30Z"
    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"
- length:
    hits.hits: 3
- match:
    hits.hits.0._id: "3"
- match:
    hits.hits.1._id: "1"
- match:
    hits.hits.2._id: "2"
---
test distance_feature query on date_nanos type:
- do:
    search:
      rest_total_hits_as_int: true
      index: "index1"
      body:
        query:
          distance_feature:
            field: "my_date_nanos"
            pivot: "100000000nanos"
            origin: "2018-02-01T00:00:00.323456789Z"
    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"
- length:
    hits.hits: 3
- match:
    hits.hits.0._id: "3"
- match:
    hits.hits.1._id: "1"
- match:
    hits.hits.2._id: "2"
---
test distance_feature query on geo_point type:
- do:
    search:
      rest_total_hits_as_int: true
      index: "index1"
      body:
        query:
          distance_feature:
            field: "my_geo"
            pivot: "1km"
            origin:
            - -71.35
            - 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"
- length:
    hits.hits: 3
- match:
    hits.hits.0._id: "3"
- match:
    hits.hits.1._id: "1"
- match:
    hits.hits.2._id: "2"
