---
setup:
- skip:
    features:
    - "close_to"
    - "headers"
    - "allowed_warnings_regex"
---
Test cartesian_bounds aggregation on point field with point:
- do:
    indices.create:
      index: "locations"
      body:
        mappings:
          properties:
            location:
              type: "point"
    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: "locations"
      id: "point_with_doc_values"
      body:
        location: "POINT(342.5 -217.6)"
    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"
- do:
    search:
      rest_total_hits_as_int: true
      index: "locations"
      size: 0
      body:
        aggs:
          my_agg:
            cartesian_bounds:
              field: "location"
    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.total: 1
- close_to:
    aggregations.my_agg.bounds.top_left.x:
      value: 342.5
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.top_left.y:
      value: -217.6
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.bottom_right.x:
      value: 342.5
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.bottom_right.y:
      value: -217.6
      error: 0.001
---
Test cartesian_bounds aggregation on shape field with point:
- do:
    indices.create:
      index: "locations"
      body:
        mappings:
          properties:
            location:
              type: "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: "locations"
      id: "point_with_doc_values"
      body:
        location: "POINT(342.5 -217.6)"
    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"
- do:
    search:
      rest_total_hits_as_int: true
      index: "locations"
      size: 0
      body:
        aggs:
          my_agg:
            cartesian_bounds:
              field: "location"
    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.total: 1
- close_to:
    aggregations.my_agg.bounds.top_left.x:
      value: 342.5
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.top_left.y:
      value: -217.6
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.bottom_right.x:
      value: 342.5
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.bottom_right.y:
      value: -217.6
      error: 0.001
---
Test cartesian_bounds aggregation on point field with points:
- do:
    indices.create:
      index: "locations"
      body:
        mappings:
          properties:
            location:
              type: "point"
    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:
    bulk:
      refresh: true
      index: "locations"
      body: "{\"index\":{}}\n{\"location\": \"POINT(491.2350 5237.4081)\", \"city\"\
        : \"Amsterdam\", \"name\": \"NEMO Science Museum\"}\n{\"index\":{}}\n{\"location\"\
        : \"POINT(490.1618 5236.9219)\", \"city\": \"Amsterdam\", \"name\": \"Museum\
        \ Het Rembrandthuis\"}\n{\"index\":{}}\n{\"location\": \"POINT(491.4722 5237.1667)\"\
        , \"city\": \"Amsterdam\", \"name\": \"Nederlands Scheepvaartmuseum\"}\n{\"\
        index\":{}}\n{\"location\": \"POINT(440.5200 5122.2900)\", \"city\": \"Antwerp\"\
        , \"name\": \"Letterenhuis\"}\n{\"index\":{}}\n{\"location\": \"POINT(233.6389\
        \ 4886.1111)\", \"city\": \"Paris\", \"name\": \"Musée du Louvre\"}\n{\"index\"\
        :{}}\n{\"location\": \"POINT(232.7000 4886.0000)\", \"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:
    - ".*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"
- do:
    search:
      rest_total_hits_as_int: true
      index: "locations"
      size: 0
      body:
        aggs:
          my_agg:
            cartesian_bounds:
              field: "location"
    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.total: 6
- close_to:
    aggregations.my_agg.bounds.top_left.x:
      value: 232.7
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.top_left.y:
      value: 5237.4081
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.bottom_right.x:
      value: 491.4722
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.bottom_right.y:
      value: 4886.0
      error: 0.001
---
Test cartesian_bounds aggregation on shape field with points:
- do:
    indices.create:
      index: "locations"
      body:
        mappings:
          properties:
            location:
              type: "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:
    bulk:
      refresh: true
      index: "locations"
      body: "{\"index\":{}}\n{\"location\": \"POINT(491.2350 5237.4081)\", \"city\"\
        : \"Amsterdam\", \"name\": \"NEMO Science Museum\"}\n{\"index\":{}}\n{\"location\"\
        : \"POINT(490.1618 5236.9219)\", \"city\": \"Amsterdam\", \"name\": \"Museum\
        \ Het Rembrandthuis\"}\n{\"index\":{}}\n{\"location\": \"POINT(491.4722 5237.1667)\"\
        , \"city\": \"Amsterdam\", \"name\": \"Nederlands Scheepvaartmuseum\"}\n{\"\
        index\":{}}\n{\"location\": \"POINT(440.5200 5122.2900)\", \"city\": \"Antwerp\"\
        , \"name\": \"Letterenhuis\"}\n{\"index\":{}}\n{\"location\": \"POINT(233.6389\
        \ 4886.1111)\", \"city\": \"Paris\", \"name\": \"Musée du Louvre\"}\n{\"index\"\
        :{}}\n{\"location\": \"POINT(232.7000 4886.0000)\", \"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:
    - ".*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"
- do:
    search:
      rest_total_hits_as_int: true
      index: "locations"
      size: 0
      body:
        aggs:
          my_agg:
            cartesian_bounds:
              field: "location"
    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.total: 6
- close_to:
    aggregations.my_agg.bounds.top_left.x:
      value: 232.7
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.top_left.y:
      value: 5237.4081
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.bottom_right.x:
      value: 491.4722
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.bottom_right.y:
      value: 4886.0
      error: 0.001
---
Test cartesian_bounds aggregation on shape field with polygon:
- do:
    indices.create:
      index: "locations"
      body:
        mappings:
          properties:
            location:
              type: "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: "locations"
      id: "big_rectangle"
      body:
        location: "POLYGON((-1000 -1000, 1000 -1000, 1000 1000, -1000 1000, -1000\
          \ -1000))"
    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"
- do:
    search:
      rest_total_hits_as_int: true
      index: "locations"
      size: 0
      body:
        aggs:
          my_agg:
            cartesian_bounds:
              field: "location"
    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.total: 1
- close_to:
    aggregations.my_agg.bounds.top_left.x:
      value: -1000.0
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.top_left.y:
      value: 1000.0
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.bottom_right.x:
      value: 1000.0
      error: 0.001
- close_to:
    aggregations.my_agg.bounds.bottom_right.y:
      value: -1000.0
      error: 0.001
