Using the geo_distance query
When you are working with geolocations, one common task is to filter results based on the distance from a location. This scenario covers very common site requirements such as:
Finding the nearest restaurant within a distance of 20 km
Finding my nearest friends within a range of 10 km
The geo_distance
query is used to achieve this goal.
Getting ready
You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
To execute curl
via the command line, you need to install curl
for your operating system.
To correctly execute the following commands, you need an index populated with the chapter_07/populate_geo.sh
geoscript available in the online code.
How to do it...
To execute a geo_distance
query, we will perform the following steps:
Searching documents in which
pin.location
is200km
away fromÂlat
 Â40
 andlon
 as Â70
 is done with a similar query:curl -XGET 'http://127...