---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "test"
      body:
        settings:
          number_of_shards: 1
        mappings:
          properties:
            geo_shape:
              type: "geo_shape"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    index:
      index: "test"
      id: "1"
      body:
        geo_shape: "POLYGON((24.04725 59.942,24.04825 59.94125,24.04875 59.94125,24.04875\
          \ 59.94175,24.048 59.9425,24.0475 59.94275,24.0465 59.94225,24.046 59.94225,24.04575\
          \ 59.9425,24.04525 59.94225,24.04725 59.942))"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] 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:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
centroid:
- do:
    search:
      rest_total_hits_as_int: true
      body:
        script_fields:
          centroid:
            script:
              source: "doc['geo_shape'].getCentroid()"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0.fields.centroid.0.lat: 59.942043484188616
- match:
    hits.hits.0.fields.centroid.0.lon: 24.047588920220733
---
bounding box:
- do:
    search:
      rest_total_hits_as_int: true
      body:
        script_fields:
          bbox:
            script:
              source: "doc['geo_shape'].getBoundingBox()"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0.fields.bbox.0.top_left.lat: 59.942749994806945
- match:
    hits.hits.0.fields.bbox.0.top_left.lon: 24.045249950140715
- match:
    hits.hits.0.fields.bbox.0.bottom_right.lat: 59.94124996941537
- match:
    hits.hits.0.fields.bbox.0.bottom_right.lon: 24.048749981448054
---
label position:
- do:
    search:
      rest_total_hits_as_int: true
      body:
        script_fields:
          label_position:
            script:
              source: "doc['geo_shape'].getLabelPosition()"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0.fields.label_position.0.lat: 59.942043484188616
- match:
    hits.hits.0.fields.label_position.0.lon: 24.047588920220733
---
bounding box points:
- do:
    search:
      rest_total_hits_as_int: true
      body:
        script_fields:
          topLeft:
            script:
              source: "doc['geo_shape'].getBoundingBox().topLeft()"
          bottomRight:
            script:
              source: "doc['geo_shape'].getBoundingBox().bottomRight()"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0.fields.topLeft.0.lat: 59.942749994806945
- match:
    hits.hits.0.fields.topLeft.0.lon: 24.045249950140715
- match:
    hits.hits.0.fields.bottomRight.0.lat: 59.94124996941537
- match:
    hits.hits.0.fields.bottomRight.0.lon: 24.048749981448054
---
dimensional type:
- do:
    search:
      rest_total_hits_as_int: true
      body:
        script_fields:
          type:
            script:
              source: "doc['geo_shape'].getDimensionalType()"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0.fields.type.0: 2
---
geoshape value:
- requires:
    cluster_features:
    - "gte_v8.9.0"
    reason: "output changed in 8.9"
- do:
    search:
      rest_total_hits_as_int: true
      body:
        script_fields:
          type:
            script:
              source: "doc['geo_shape'].get(0)"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0.fields.type.0: "<unserializable>"
- do:
    search:
      rest_total_hits_as_int: true
      body:
        script_fields:
          type:
            script:
              source: "field('geo_shape').get(null)"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0.fields.type.0: "<unserializable>"
- do:
    search:
      rest_total_hits_as_int: true
      body:
        script_fields:
          type:
            script:
              source: "/* avoid yaml stash */ $('geo_shape', null)"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0.fields.type.0: "<unserializable>"
---
diagonal length:
- do:
    search:
      rest_total_hits_as_int: true
      body:
        script_fields:
          width:
            script:
              source: "doc['geo_shape'].getMercatorWidth()"
          height:
            script:
              source: "doc['geo_shape'].getMercatorHeight()"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.hits.0.fields.width.0: 389.62170283915475
- match:
    hits.hits.0.fields.height.0: 333.37976841442287
