setup:
  - do:
      indices.create:
        index: locations
        body:
          settings:
            number_of_shards: 3
          mappings:
            properties:
              location:
                type: geo_point

  - 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"}'
  - do:
      indices.refresh: {}

---
"Test geohash":

  - do:
      search:
        index: locations
        size: 10
        body:
          query:
            geo_grid:
              location:
                geohash: "u173zt90zc"

  - 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"

  - 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"

  - 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)"    }
