---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    cluster_features:
    - "gte_v8.10.0"
    reason: "position metric introduced in 8.8.0, synthetic source shows up in the\
      \ mapping in 8.10 and on, may trigger assert failures in mixed cluster tests"
- do:
    indices.create:
      index: "locations"
      body:
        settings:
          index:
            mode: "time_series"
            routing_path:
            - "city"
            - "name"
            time_series:
              start_time: "2023-01-01T00:00:00Z"
              end_time: "2024-01-01T00:00:00Z"
        mappings:
          properties:
            '@timestamp':
              type: "date"
            city:
              type: "keyword"
              time_series_dimension: true
            name:
              type: "keyword"
              time_series_dimension: true
            location:
              type: "geo_point"
              time_series_metric: "position"
    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:
      index: "locations"
      refresh: true
      body: "{\"index\":{}}\n{\"@timestamp\": \"2023-01-01T12:00:00Z\", \"location\"\
        : \"POINT(4.912350 52.374081)\", \"city\": \"Amsterdam\", \"name\": \"NEMO\
        \ Science Museum\"}\n{\"index\":{}}\n{\"@timestamp\": \"2023-01-02T12:00:00Z\"\
        , \"location\": \"POINT(4.901618 52.369219)\", \"city\": \"Amsterdam\", \"\
        name\": \"Museum Het Rembrandthuis\"}\n{\"index\":{}}\n{\"@timestamp\": \"\
        2023-01-03T12:00:00Z\", \"location\": \"POINT(4.914722 52.371667)\", \"city\"\
        : \"Amsterdam\", \"name\": \"Nederlands Scheepvaartmuseum\"}\n{\"index\":{}}\n\
        {\"@timestamp\": \"2023-01-04T12:00:00Z\", \"location\": \"POINT(4.405200\
        \ 51.222900)\", \"city\": \"Antwerp\", \"name\": \"Letterenhuis\"}\n{\"index\"\
        :{}}\n{\"@timestamp\": \"2023-01-05T12:00:00Z\", \"location\": \"POINT(2.336389\
        \ 48.861111)\", \"city\": \"Paris\", \"name\": \"Musée du Louvre\"}\n{\"index\"\
        :{}}\n{\"@timestamp\": \"2023-01-06T12:00:00Z\", \"location\": \"POINT(2.327000\
        \ 48.860000)\", \"city\": \"Paris\", \"name\": \"Musée dOrsay\"}\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:
    indices.refresh: {}
    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"
---
multi-valued fields unsupported:
- requires:
    test_runner_features: "contains"
    cluster_features:
    - "gte_v8.8.0"
    reason: "position metric introduced in 8.8.0"
- do:
    bulk:
      index: "locations"
      refresh: true
      body: "{\"index\" : {}}\n{\"@timestamp\": \"2023-01-01T12:00:00Z\", \"city\"\
        : \"Rock\", \"name\": \"On\", \"location\": {\"lat\": 13.0, \"lon\" : 34.0}\
        \ }\n{\"index\" : {}}\n{\"@timestamp\": \"2023-01-01T12:00:00Z\", \"city\"\
        : \"Hey\", \"name\": \"There\", \"location\": [{\"lat\": 13.0, \"lon\" : 34.0}]\
        \ }\n{\"index\" : {}}\n{\"@timestamp\": \"2023-01-01T12:00:00Z\", \"city\"\
        : \"Boo\", \"name\": \"Hoo\", \"location\": [{\"lat\": 13.0, \"lon\" : 34.0},\
        \ {\"lat\": 14.0, \"lon\" : 35.0}] }\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"
- match:
    errors: true
- match:
    items.0.index.result: "created"
- match:
    items.1.index.result: "created"
- contains:
    items.2.index.error.reason: "failed to parse: field type for [location] does not\
      \ accept more than single value"
---
avg aggregation on position field unsupported:
- requires:
    cluster_features:
    - "gte_v8.10.0"
    reason: "position metric introduced in 8.8.0, but exception message changed in\
      \ 8.10.0"
- do:
    catch: "/Field \\[location\\] of type \\[geo_point\\]\\[position\\] is not supported\
      \ for aggregation \\[avg\\]/"
    search:
      index: "locations"
      body:
        aggs:
          avg_location:
            avg:
              field: "location"
    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"
---
geo_bounds on position field:
- requires:
    cluster_features:
    - "gte_v8.8.0"
    reason: "position metric introduced in 8.8.0"
    test_runner_features: "close_to"
- do:
    search:
      index: "locations"
      rest_total_hits_as_int: true
      body:
        aggregations:
          view_port:
            geo_bounds:
              field: "location"
              wrap_longitude: true
    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: 6
- close_to:
    aggregations.view_port.bounds.top_left.lat:
      value: 52.374081
      error: 1.0E-5
- close_to:
    aggregations.view_port.bounds.top_left.lon:
      value: 2.327
      error: 1.0E-5
- close_to:
    aggregations.view_port.bounds.bottom_right.lat:
      value: 48.86
      error: 1.0E-5
- close_to:
    aggregations.view_port.bounds.bottom_right.lon:
      value: 4.914722
      error: 1.0E-5
---
geo_centroid on position field:
- requires:
    cluster_features:
    - "gte_v8.8.0"
    reason: "position metric introduced in 8.8.0"
    test_runner_features: "close_to"
- do:
    search:
      rest_total_hits_as_int: true
      body:
        aggregations:
          centroid:
            geo_centroid:
              field: "location"
    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: 6
- match:
    aggregations.centroid.location.lat: 51.00982965203002
- match:
    aggregations.centroid.location.lon: 3.9662131341174245
- match:
    aggregations.centroid.count: 6
---
geo bounding box query:
- requires:
    cluster_features:
    - "gte_v8.8.0"
    reason: "position metric introduced in 8.8.0"
- do:
    search:
      index: "locations"
      body:
        query:
          geo_bounding_box:
            location:
              top_left:
                lat: 53
                lon: 4
              bottom_right:
                lat: 50
                lon: 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"
- match:
    hits.total.value: 4
---
geo shape intersects query:
- requires:
    cluster_features:
    - "gte_v8.8.0"
    reason: "position metric introduced in 8.8.0"
- do:
    search:
      index: "locations"
      body:
        query:
          geo_shape:
            location:
              shape:
                type: "envelope"
                coordinates:
                - - 0
                  - 50
                - - 4
                  - 45
    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
---
geo shape within query:
- requires:
    cluster_features:
    - "gte_v8.8.0"
    reason: "position metric introduced in 8.8.0"
- do:
    search:
      index: "locations"
      body:
        query:
          geo_shape:
            location:
              shape:
                type: "envelope"
                coordinates:
                - - 0
                  - 50
                - - 4
                  - 45
              relation: "within"
    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
---
geo shape disjoint query:
- requires:
    cluster_features:
    - "gte_v8.8.0"
    reason: "position metric introduced in 8.8.0"
- do:
    search:
      index: "locations"
      body:
        query:
          geo_shape:
            location:
              shape:
                type: "envelope"
                coordinates:
                - - 0
                  - 50
                - - 4
                  - 45
              relation: "disjoint"
    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: 4
---
geo shape contains query:
- requires:
    cluster_features:
    - "gte_v8.8.0"
    reason: "position metric introduced in 8.8.0"
- do:
    search:
      index: "locations"
      body:
        query:
          geo_shape:
            location:
              shape:
                type: "envelope"
                coordinates:
                - - 0
                  - 50
                - - 4
                  - 45
              relation: "contains"
    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: 0
---
geo distance query:
- requires:
    cluster_features:
    - "gte_v8.8.0"
    reason: "position metric introduced in 8.8.0"
- do:
    search:
      index: "locations"
      body:
        query:
          geo_distance:
            distance: "100km"
            location:
              lat: 52
              lon: 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"
- match:
    hits.total.value: 4
---
geo_distance sort:
- requires:
    cluster_features:
    - "gte_v8.8.0"
    reason: "position metric introduced in 8.8.0"
    test_runner_features: "close_to"
- do:
    search:
      index: "locations"
      body:
        sort:
          _geo_distance:
            location:
              lat: 52.0
              lon: 5.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"
- match:
    hits.total.value: 6
- close_to:
    hits.hits.0._source.location.lat:
      value: 52.369219
      error: 1.0E-5
- close_to:
    hits.hits.0._source.location.lon:
      value: 4.901618
      error: 1.0E-5
- close_to:
    hits.hits.1._source.location.lat:
      value: 52.371667
      error: 1.0E-5
- close_to:
    hits.hits.1._source.location.lon:
      value: 4.914722
      error: 1.0E-5
- close_to:
    hits.hits.2._source.location.lat:
      value: 52.374081
      error: 1.0E-5
- close_to:
    hits.hits.2._source.location.lon:
      value: 4.91235
      error: 1.0E-5
- close_to:
    hits.hits.3._source.location.lat:
      value: 51.2229
      error: 1.0E-5
- close_to:
    hits.hits.3._source.location.lon:
      value: 4.4052
      error: 1.0E-5
- close_to:
    hits.hits.4._source.location.lat:
      value: 48.861111
      error: 1.0E-5
- close_to:
    hits.hits.4._source.location.lon:
      value: 2.336389
      error: 1.0E-5
- close_to:
    hits.hits.5._source.location.lat:
      value: 48.86
      error: 1.0E-5
- close_to:
    hits.hits.5._source.location.lon:
      value: 2.327
      error: 1.0E-5
---
distance_feature query:
- requires:
    cluster_features:
    - "gte_v8.8.0"
    reason: "position metric introduced in 8.8.0"
    test_runner_features: "close_to"
- do:
    search:
      index: "locations"
      body:
        query:
          bool:
            should:
              distance_feature:
                field: "location"
                pivot: "100km"
                origin:
                - 5.0
                - 52.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"
- match:
    hits.total.value: 6
- close_to:
    hits.hits.0._source.location.lat:
      value: 52.369219
      error: 1.0E-5
- close_to:
    hits.hits.0._source.location.lon:
      value: 4.901618
      error: 1.0E-5
- close_to:
    hits.hits.1._source.location.lat:
      value: 52.371667
      error: 1.0E-5
- close_to:
    hits.hits.1._source.location.lon:
      value: 4.914722
      error: 1.0E-5
- close_to:
    hits.hits.2._source.location.lat:
      value: 52.374081
      error: 1.0E-5
- close_to:
    hits.hits.2._source.location.lon:
      value: 4.91235
      error: 1.0E-5
- close_to:
    hits.hits.3._source.location.lat:
      value: 51.2229
      error: 1.0E-5
- close_to:
    hits.hits.3._source.location.lon:
      value: 4.4052
      error: 1.0E-5
- close_to:
    hits.hits.4._source.location.lat:
      value: 48.861111
      error: 1.0E-5
- close_to:
    hits.hits.4._source.location.lon:
      value: 2.336389
      error: 1.0E-5
- close_to:
    hits.hits.5._source.location.lat:
      value: 48.86
      error: 1.0E-5
- close_to:
    hits.hits.5._source.location.lon:
      value: 2.327
      error: 1.0E-5
