Aggregating restaurants based on their nearness

In the previous example, we saw the aggregation of restaurants based on their distance from the current point to three different categories. Now, we can consider another scenario in which we classify the restaurants on the basis of the geohash grids that they belong to. This kind of classification can be advantageous if the user would like to get a geographical picture of how the restaurants are distributed.

Here is the code for a geohash-based aggregation of restaurants:

curl -XPOST 'http://localhost:9200/restaurants/_search?pretty' -d '{ 
  "size": 0,
  "aggs": {
    "DifferentGrids": {
      "geohash_grid": {
        "field": "location",
        "precision": 6
      },
      "aggs": {
        "restaurants": {
          "top_hits": {}
        }
      }
    }
  }
}'

You can see ...

Get Elasticsearch Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.