2015-08-06 11:24:29 -04:00
[[lat-lon]]
=== `lat_lon`
2016-08-02 17:35:31 -04:00
deprecated[5.0.0, ????????]
// https://github.com/elastic/elasticsearch/issues/19792
2015-08-06 11:24:29 -04:00
<<geo-queries,Geo-queries>> are usually performed by plugging the value of
each <<geo-point,`geo_point`>> field into a formula to determine whether it
falls into the required area or not. Unlike most queries, the inverted index
is not involved.
Setting `lat_lon` to `true` causes the latitude and longitude values to be
indexed as numeric fields (called `.lat` and `.lon`). These fields can be used
by the <<query-dsl-geo-bounding-box-query,`geo_bounding_box`>> and
<<query-dsl-geo-distance-query,`geo_distance`>> queries instead of
2016-08-02 17:35:31 -04:00
performing in-memory calculations. So this mapping:
2015-08-06 11:24:29 -04:00
[source,js]
--------------------------------------------------
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"location": {
"type": "geo_point",
"lat_lon": true <1>
}
}
}
}
}
2016-08-02 17:35:31 -04:00
--------------------------------------------------
// TEST[warning:geo_point lat_lon parameter is deprecated and will be removed in the next major release]
<1> Setting `lat_lon` to true indexes the geo-point in the `location.lat` and `location.lon` fields.
2016-08-23 13:43:35 -04:00
With this document:
2015-08-06 11:24:29 -04:00
2016-08-02 17:35:31 -04:00
[source,js]
--------------------------------------------------
PUT my_index/my_type/1?refresh
2015-08-06 11:24:29 -04:00
{
"location": {
"lat": 41.12,
"lon": -71.34
}
}
2016-08-23 13:43:35 -04:00
--------------------------------------------------
// CONSOLE
// TEST[continued]
2015-08-06 11:24:29 -04:00
2016-08-23 13:43:35 -04:00
Allows this query:
2015-08-06 11:24:29 -04:00
2016-08-23 13:43:35 -04:00
[source,js]
--------------------------------------------------
2015-08-06 11:24:29 -04:00
GET my_index/_search
{
"query": {
"geo_distance": {
"location": {
"lat": 41,
"lon": -71
},
"distance": "50km",
2016-08-02 17:35:31 -04:00
"optimize_bbox": "indexed" <1>
2015-08-06 11:24:29 -04:00
}
}
}
--------------------------------------------------
2016-05-09 09:42:23 -04:00
// CONSOLE
2016-08-02 17:35:31 -04:00
// TEST[continued]
2016-08-23 13:43:35 -04:00
// TEST[warning:Deprecated field [optimize_bbox] used, replaced by [no replacement: `optimize_bbox` is no longer supported due to recent improvements]]
2016-08-02 17:35:31 -04:00
<1> The `indexed` option tells the geo-distance query to use the inverted index instead of the in-memory calculation.
2015-08-06 11:24:29 -04:00
Whether the in-memory or indexed operation performs better depends both on
your dataset and on the types of queries that you are running.
NOTE: The `lat_lon` option only makes sense for single-value `geo_point`
fields. It will not work with arrays of geo-points.