---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "locations"
      body:
        settings:
          number_of_shards: 3
        mappings:
          properties:
            location:
              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:
    bulk:
      refresh: true
      index: "locations"
      body: "{\"index\":{}}\n{\"location\": \"POINT(4.912350 52.374081)\", \"city\"\
        : \"Amsterdam\", \"name\": \"NEMO Science Museum\"}\n{\"index\":{}}\n{\"location\"\
        : \"POINT(4.901618 52.369219)\", \"city\": \"Amsterdam\", \"name\": \"Museum\
        \ Het Rembrandthuis\"}\n{\"index\":{}}\n{\"location\": \"POINT(4.914722 52.371667)\"\
        , \"city\": \"Amsterdam\", \"name\": \"Nederlands Scheepvaartmuseum\"}\n{\"\
        index\":{}}\n{\"location\": \"POINT(4.405200 51.222900)\", \"city\": \"Antwerp\"\
        , \"name\": \"Letterenhuis\"}\n{\"index\":{}}\n{\"location\": \"POINT(2.336389\
        \ 48.861111)\", \"city\": \"Paris\", \"name\": \"Musée du Louvre\"}\n{\"index\"\
        :{}}\n{\"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:
    - ".*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"
---
Test geohex_grid on geo_shape field with defaults:
- do:
    search:
      index: "locations"
      size: 0
      body:
        aggs:
          grid:
            geohex_grid:
              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.value: 6
- length:
    aggregations.grid.buckets: 3
- match:
    aggregations.grid.buckets.0.key: "85196953fffffff"
- match:
    aggregations.grid.buckets.0.doc_count: 3
- match:
    aggregations.grid.buckets.1.key: "851fb467fffffff"
- match:
    aggregations.grid.buckets.1.doc_count: 2
- match:
    aggregations.grid.buckets.2.key: "851fa4c7fffffff"
- match:
    aggregations.grid.buckets.2.doc_count: 1
---
Test geohex_grid on geo_shape field with precision:
- do:
    search:
      index: "locations"
      size: 0
      body:
        aggs:
          grid:
            geohex_grid:
              field: "location"
              precision: 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.total.value: 6
- length:
    aggregations.grid.buckets: 2
- match:
    aggregations.grid.buckets.0.key: "801ffffffffffff"
- match:
    aggregations.grid.buckets.0.doc_count: 4
- match:
    aggregations.grid.buckets.1.key: "8019fffffffffff"
- match:
    aggregations.grid.buckets.1.doc_count: 2
---
Test geohex_grid on geo_shape field with size:
- do:
    search:
      index: "locations"
      size: 0
      body:
        aggs:
          grid:
            geohex_grid:
              field: "location"
              size: 1
    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.value: 6
- length:
    aggregations.grid.buckets: 1
- match:
    aggregations.grid.buckets.0.key: "85196953fffffff"
- match:
    aggregations.grid.buckets.0.doc_count: 3
---
Test geohex_grid on geo_shape field with shard size:
- do:
    search:
      index: "locations"
      size: 0
      body:
        aggs:
          grid:
            geohex_grid:
              field: "location"
              shard_size: 10
    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.value: 6
- length:
    aggregations.grid.buckets: 3
- match:
    aggregations.grid.buckets.0.key: "85196953fffffff"
- match:
    aggregations.grid.buckets.0.doc_count: 3
- match:
    aggregations.grid.buckets.1.key: "851fb467fffffff"
- match:
    aggregations.grid.buckets.1.doc_count: 2
- match:
    aggregations.grid.buckets.2.key: "851fa4c7fffffff"
- match:
    aggregations.grid.buckets.2.doc_count: 1
---
Test geohex_grid on geo_shape field with bounds:
- do:
    search:
      index: "locations"
      size: 0
      body:
        aggs:
          grid:
            geohex_grid:
              field: "location"
              bounds:
                top_left: "POINT (4.9 52.4)"
                bottom_right: "POINT (5.0 52.3)"
    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.value: 6
- length:
    aggregations.grid.buckets: 1
- match:
    aggregations.grid.buckets.0.key: "85196953fffffff"
- match:
    aggregations.grid.buckets.0.doc_count: 3
