---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "locations"
      body:
        settings:
          number_of_shards: 3
        mappings:
          properties:
            location:
              type: "geo_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
      body:
      - index:
          _index: "locations"
          _id: "1"
      - "{\"location\": \"POINT(4.912350 52.374081)\", \"city\": \"Amsterdam\", \"\
        name\": \"NEMO Science Museum\"}"
      - index:
          _index: "locations"
          _id: "2"
      - "{\"location\": \"POINT(4.901618 52.369219)\", \"city\": \"Amsterdam\", \"\
        name\": \"Museum Het Rembrandthuis\"}"
      - index:
          _index: "locations"
          _id: "3"
      - "{\"location\": \"POINT(4.914722 52.371667)\", \"city\": \"Amsterdam\", \"\
        name\": \"Nederlands Scheepvaartmuseum\"}"
      - index:
          _index: "locations"
          _id: "4"
      - "{\"location\": \"POINT(4.405200 51.222900)\", \"city\": \"Antwerp\", \"name\"\
        : \"Letterenhuis\"}"
      - index:
          _index: "locations"
          _id: "5"
      - "{\"location\": \"POINT(2.336389 48.861111)\", \"city\": \"Paris\", \"name\"\
        : \"Musée du Louvre\"}"
      - index:
          _index: "locations"
          _id: "6"
      - "{\"location\": \"POINT(2.327000 48.860000)\", \"city\": \"Paris\", \"name\"\
        : \"Musée dOrsay\"}"
    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 geohash:
- do:
    search:
      index: "locations"
      size: 10
      body:
        query:
          geo_grid:
            location:
              geohash: "u173zt90zc"
    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: 1
- match:
    hits.hits.0._id: "2"
- match:
    hits.hits.0._source.city: "Amsterdam"
- match:
    hits.hits.0._source.name: "Museum Het Rembrandthuis"
- match:
    hits.hits.0._source.location: "POINT(4.901618 52.369219)"
---
Test geotile:
- do:
    search:
      index: "locations"
      size: 10
      body:
        query:
          geo_grid:
            location:
              geotile: "22/2154259/1378425"
    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: 1
- match:
    hits.hits.0._id: "2"
- match:
    hits.hits.0._source.city: "Amsterdam"
- match:
    hits.hits.0._source.name: "Museum Het Rembrandthuis"
- match:
    hits.hits.0._source.location: "POINT(4.901618 52.369219)"
---
Test geohex:
- do:
    search:
      index: "locations"
      size: 10
      body:
        query:
          geo_grid:
            location:
              geohex: "8f1969c9b261656"
    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: 1
- match:
    hits.hits.0._id: "2"
- match:
    hits.hits.0._source.city: "Amsterdam"
- match:
    hits.hits.0._source.name: "Museum Het Rembrandthuis"
- match:
    hits.hits.0._source.location: "POINT(4.901618 52.369219)"
