WARNING: Version 2.4 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Geo Distance Query
editGeo Distance Query
editFilters documents that include only hits that exists within a specific distance from a geo point. Assuming the following indexed json:
{ "pin" : { "location" : { "lat" : 40.12, "lon" : -71.34 } } }
Then the following simple query can be executed with a geo_distance
filter:
{ "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_distance" : { "distance" : "200km", "pin.location" : { "lat" : 40, "lon" : -70 } } } } }
Accepted Formats
editIn much the same way the geo_point
type can accept different
representations of the geo point, the filter can accept it as well:
Lat Lon As Properties
edit{ "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_distance" : { "distance" : "12km", "pin.location" : { "lat" : 40, "lon" : -70 } } } } }
Lat Lon As Array
editFormat in [lon, lat]
, note, the order of lon/lat here in order to
conform with GeoJSON.
{ "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_distance" : { "distance" : "12km", "pin.location" : [-70, 40] } } } }
Lat Lon As String
editFormat in lat,lon
.
{ "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_distance" : { "distance" : "12km", "pin.location" : "40,-70" } } } }
Geohash
edit{ "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_distance" : { "distance" : "12km", "pin.location" : "drm3btev3e86" } } } }
Options
editThe following are options allowed on the filter:
|
The radius of the circle centred on the specified location. Points which
fall into this circle are considered to be matches. The |
|
How to compute the distance. Can either be |
|
Whether to use the optimization of first running a bounding box check
before the distance check. Defaults to |
|
Optional name field to identify the query |
|
Set to |
geo_point Type
editThe filter requires the geo_point
type to be set on the relevant
field.
Multi Location Per Document
editThe geo_distance
filter can work with multiple locations / points per
document. Once a single location / point matches the filter, the
document will be included in the filter.