|
@@ -14,7 +14,7 @@ Fields of type `geo_point` accept latitude-longitude pairs, which can be used:
|
|
|
* to integrate distance into a document's <<query-dsl-function-score-query,relevance score>>.
|
|
|
* to <<geo-sorting,sort>> documents by distance.
|
|
|
|
|
|
-There are five ways that a geopoint may be specified, as demonstrated below:
|
|
|
+There are six ways that a geopoint may be specified, as demonstrated below:
|
|
|
|
|
|
[source,console]
|
|
|
--------------------------------------------------
|
|
@@ -31,7 +31,7 @@ PUT my-index-000001
|
|
|
|
|
|
PUT my-index-000001/_doc/1
|
|
|
{
|
|
|
- "text": "Geopoint as an object",
|
|
|
+ "text": "Geopoint as an object with 'lat' and 'lon' keys",
|
|
|
"location": { <1>
|
|
|
"lat": 41.12,
|
|
|
"lon": -71.34
|
|
@@ -40,32 +40,41 @@ PUT my-index-000001/_doc/1
|
|
|
|
|
|
PUT my-index-000001/_doc/2
|
|
|
{
|
|
|
- "text": "Geopoint as a string",
|
|
|
- "location": "41.12,-71.34" <2>
|
|
|
+ "text": "Geopoint as an object using GeoJSON format",
|
|
|
+ "location": { <2>
|
|
|
+ "type": "Point",
|
|
|
+ "coordinates": [-71.34, 41.12]
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
PUT my-index-000001/_doc/3
|
|
|
{
|
|
|
- "text": "Geopoint as a geohash",
|
|
|
- "location": "drm3btev3e86" <3>
|
|
|
+ "text": "Geopoint as a string",
|
|
|
+ "location": "41.12,-71.34" <3>
|
|
|
}
|
|
|
|
|
|
PUT my-index-000001/_doc/4
|
|
|
{
|
|
|
- "text": "Geopoint as an array",
|
|
|
- "location": [ -71.34, 41.12 ] <4>
|
|
|
+ "text": "Geopoint as a geohash",
|
|
|
+ "location": "drm3btev3e86" <4>
|
|
|
}
|
|
|
|
|
|
PUT my-index-000001/_doc/5
|
|
|
+{
|
|
|
+ "text": "Geopoint as an array",
|
|
|
+ "location": [ -71.34, 41.12 ] <5>
|
|
|
+}
|
|
|
+
|
|
|
+PUT my-index-000001/_doc/6
|
|
|
{
|
|
|
"text": "Geopoint as a WKT POINT primitive",
|
|
|
- "location" : "POINT (-71.34 41.12)" <5>
|
|
|
+ "location" : "POINT (-71.34 41.12)" <6>
|
|
|
}
|
|
|
|
|
|
GET my-index-000001/_search
|
|
|
{
|
|
|
"query": {
|
|
|
- "geo_bounding_box": { <6>
|
|
|
+ "geo_bounding_box": { <7>
|
|
|
"location": {
|
|
|
"top_left": {
|
|
|
"lat": 42,
|
|
@@ -82,22 +91,26 @@ GET my-index-000001/_search
|
|
|
--------------------------------------------------
|
|
|
|
|
|
<1> Geopoint expressed as an object, with `lat` and `lon` keys.
|
|
|
-<2> Geopoint expressed as a string with the format: `"lat,lon"`.
|
|
|
-<3> Geopoint expressed as a geohash.
|
|
|
-<4> Geopoint expressed as an array with the format: [ `lon`, `lat`]
|
|
|
-<5> Geopoint expressed as a https://docs.opengeospatial.org/is/12-063r5/12-063r5.html[Well-Known Text]
|
|
|
+<2> Geopoint expressed as an object, in https://geojson.org/[GeoJSON] format, with `type` and `coordinates` keys.
|
|
|
+<3> Geopoint expressed as a string with the format: `"lat,lon"`.
|
|
|
+<4> Geopoint expressed as a geohash.
|
|
|
+<5> Geopoint expressed as an array with the format: [ `lon`, `lat`]
|
|
|
+<6> Geopoint expressed as a https://docs.opengeospatial.org/is/12-063r5/12-063r5.html[Well-Known Text]
|
|
|
POINT with the format: `"POINT(lon lat)"`
|
|
|
-<6> A geo-bounding box query which finds all geopoints that fall inside the box.
|
|
|
+<7> A geo-bounding box query which finds all geopoints that fall inside the box.
|
|
|
|
|
|
[IMPORTANT]
|
|
|
.Geopoints expressed as an array or string
|
|
|
==================================================
|
|
|
|
|
|
Please note that string geopoints are ordered as `lat,lon`, while array
|
|
|
-geopoints are ordered as the reverse: `lon,lat`.
|
|
|
+geopoints, GeoJSON and WKT are ordered as the reverse: `lon,lat`.
|
|
|
|
|
|
-Originally, `lat,lon` was used for both array and string, but the array
|
|
|
-format was changed early on to conform to the format used by GeoJSON.
|
|
|
+The reasons for this are historical. Geographers traditionally write `latitude`
|
|
|
+before `longitude`, while recent formats specified for geographic data like
|
|
|
+https://geojson.org/[GeoJSON] and https://docs.opengeospatial.org/is/12-063r5/12-063r5.html[Well-Known Text]
|
|
|
+order `longitude` before `latitude` (easting before northing) in order to match
|
|
|
+the mathematical convention of ordering `x` before `y`.
|
|
|
|
|
|
==================================================
|
|
|
|