@@ -14,7 +14,7 @@ Fields of type `geo_point` accept latitude-longitude pairs, which can be used:
14
14
* to integrate distance into a document's <<query-dsl-function-score-query,relevance score>>.
15
15
* to <<geo-sorting,sort>> documents by distance.
16
16
17
- There are five ways that a geopoint may be specified, as demonstrated below:
17
+ There are six ways that a geopoint may be specified, as demonstrated below:
18
18
19
19
[source,console]
20
20
--------------------------------------------------
@@ -31,7 +31,7 @@ PUT my-index-000001
31
31
32
32
PUT my-index-000001/_doc/1
33
33
{
34
- "text": "Geopoint as an object",
34
+ "text": "Geopoint as an object with 'lat' and 'lon' keys ",
35
35
"location": { <1>
36
36
"lat": 41.12,
37
37
"lon": -71.34
@@ -40,32 +40,41 @@ PUT my-index-000001/_doc/1
40
40
41
41
PUT my-index-000001/_doc/2
42
42
{
43
- "text": "Geopoint as a string",
44
- "location": "41.12,-71.34" <2>
43
+ "text": "Geopoint as an object using GeoJSON format",
44
+ "location": { <2>
45
+ "type": "Point",
46
+ "coordinates": [-71.34, 41.12]
47
+ }
45
48
}
46
49
47
50
PUT my-index-000001/_doc/3
48
51
{
49
- "text": "Geopoint as a geohash ",
50
- "location": "drm3btev3e86 " <3>
52
+ "text": "Geopoint as a string ",
53
+ "location": "41.12,-71.34 " <3>
51
54
}
52
55
53
56
PUT my-index-000001/_doc/4
54
57
{
55
- "text": "Geopoint as an array ",
56
- "location": [ -71.34, 41.12 ] <4>
58
+ "text": "Geopoint as a geohash ",
59
+ "location": "drm3btev3e86" <4>
57
60
}
58
61
59
62
PUT my-index-000001/_doc/5
63
+ {
64
+ "text": "Geopoint as an array",
65
+ "location": [ -71.34, 41.12 ] <5>
66
+ }
67
+
68
+ PUT my-index-000001/_doc/6
60
69
{
61
70
"text": "Geopoint as a WKT POINT primitive",
62
- "location" : "POINT (-71.34 41.12)" <5 >
71
+ "location" : "POINT (-71.34 41.12)" <6 >
63
72
}
64
73
65
74
GET my-index-000001/_search
66
75
{
67
76
"query": {
68
- "geo_bounding_box": { <6 >
77
+ "geo_bounding_box": { <7 >
69
78
"location": {
70
79
"top_left": {
71
80
"lat": 42,
@@ -82,22 +91,26 @@ GET my-index-000001/_search
82
91
--------------------------------------------------
83
92
84
93
<1> Geopoint expressed as an object, with `lat` and `lon` keys.
85
- <2> Geopoint expressed as a string with the format: `"lat,lon"`.
86
- <3> Geopoint expressed as a geohash.
87
- <4> Geopoint expressed as an array with the format: [ `lon`, `lat`]
88
- <5> Geopoint expressed as a https://docs.opengeospatial.org/is/12-063r5/12-063r5.html[Well-Known Text]
94
+ <2> Geopoint expressed as an object, in https://geojson.org/[GeoJSON] format, with `type` and `coordinates` keys.
95
+ <3> Geopoint expressed as a string with the format: `"lat,lon"`.
96
+ <4> Geopoint expressed as a geohash.
97
+ <5> Geopoint expressed as an array with the format: [ `lon`, `lat`]
98
+ <6> Geopoint expressed as a https://docs.opengeospatial.org/is/12-063r5/12-063r5.html[Well-Known Text]
89
99
POINT with the format: `"POINT(lon lat)"`
90
- <6 > A geo-bounding box query which finds all geopoints that fall inside the box.
100
+ <7 > A geo-bounding box query which finds all geopoints that fall inside the box.
91
101
92
102
[IMPORTANT]
93
103
.Geopoints expressed as an array or string
94
104
==================================================
95
105
96
106
Please note that string geopoints are ordered as `lat,lon`, while array
97
- geopoints are ordered as the reverse: `lon,lat`.
107
+ geopoints, GeoJSON and WKT are ordered as the reverse: `lon,lat`.
98
108
99
- Originally, `lat,lon` was used for both array and string, but the array
100
- format was changed early on to conform to the format used by GeoJSON.
109
+ The reasons for this are historical. Geographers traditionally write `latitude`
110
+ before `longitude`, while recent formats specified for geographic data like
111
+ https://geojson.org/[GeoJSON] and https://docs.opengeospatial.org/is/12-063r5/12-063r5.html[Well-Known Text]
112
+ order `longitude` before `latitude` (easting before northing) in order to match
113
+ the mathematical convention of ordering `x` before `y`.
101
114
102
115
==================================================
103
116
0 commit comments