Book Image

ElasticSearch Blueprints

Book Image

ElasticSearch Blueprints

Overview of this book

Table of Contents (15 chapters)
Elasticsearch Blueprints
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

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 from the preceding code that we used the geohash aggregation, which is named as DifferentGrids and the precision here, is to be set as 6. The precision field value can...