Using geo distance filter
When you are working with geolocations, one of the most common tasks is to filter results based on their distance from a location. This scenario covers the following common site requirements:
- Finding the nearest restaurant in a 20 km distance
- Finding your nearest friends in a 10 km range
The geo_distance
filter is used to achieve this goal.
Getting ready
You need a working ElasticSearch cluster and an index populated with the GeoScript chapter_05/geo/populate_geo.sh
, available in the code bundle for this book.
How to do it...
Search for documents in which the pin.location
is 200 km away from latitude 40, longitude 70, as follows:
curl -XGET 'http://127.0.0.1:9200/test-mindex/_search?pretty' -d '{ "query": { "filtered": {
Get ElasticSearch Cookbook - Second Edition 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.