Skip to content

Commit 68f4322

Browse files
Added documentation on GeoJSON format for points and geo-points (#86066)
* Added documentation on GeoJSON format for points And geo-points. * Fixed some small mistakes in painless geo-point
1 parent 71c4c68 commit 68f4322

File tree

4 files changed

+67
-36
lines changed

4 files changed

+67
-36
lines changed

docs/painless/painless-contexts/painless-runtime-fields-context.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ about how to use runtime fields.
1515
Accepts the values from the script valuation. Scripts can call the
1616
`emit` method multiple times to emit multiple values.
1717
+
18-
The `emit` method applies only to scripts used in a
18+
The `emit` method applies only to scripts used in a
1919
<<painless-execute-runtime-context,runtime fields context>>.
2020
+
2121
IMPORTANT: The `emit` method cannot accept `null` values. Do not call this
@@ -30,7 +30,7 @@ The signature for `emit` depends on the `type` of the field.
3030
`boolean`:: `emit(boolean)`
3131
`date`:: `emit(long)`
3232
`double`:: `emit(double)`
33-
`geo_point`:: `emit(double lat, double long)`
33+
`geo_point`:: `emit(double lat, double lon)`
3434
`ip`:: `emit(String)`
3535
`long`:: `emit(long)`
3636
`keyword`:: `emit(String)`

docs/painless/painless-guide/painless-execute-script.asciidoc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ sorted list of `double` values. See
7777
<<painless-runtime-double,double_field context>>.
7878
7979
`geo_point_field`::
80-
The context for {ref}/geo-point.html[`geo-point` fields]. `emit` takes a
81-
`geo-point` value and the script returns coordinates for the geo point. See
80+
The context for {ref}/geo-point.html[`geo-point` fields]. `emit` takes two double
81+
parameters, the latitude and longitude values, and the script returns an object in
82+
GeoJSON format containing the coordinates for the geo point. See
8283
<<painless-runtime-geo,geo_point_field context>>.
8384
8485
`ip_field`::
@@ -589,7 +590,7 @@ PUT /my-index-000001/
589590
"lat": {
590591
"type": "double"
591592
},
592-
"lon": {
593+
"lon": {
593594
"type": "double"
594595
}
595596
}
@@ -598,7 +599,7 @@ PUT /my-index-000001/
598599
----
599600

600601
You can then use the `geo_point_field` runtime field context to write a script
601-
that retrieves the `lat` and `long` values.
602+
that retrieves the `lat` and `lon` values.
602603

603604
[source,console]
604605
----
@@ -621,7 +622,7 @@ POST /_scripts/painless/_execute
621622
----
622623
// TEST[continued]
623624

624-
Because this you're working with a geo-point field type, the response includes
625+
Because you're working with a geo-point field type, the response includes
625626
results that are formatted as `coordinates`.
626627

627628
[source,console-result]
@@ -639,6 +640,10 @@ results that are formatted as `coordinates`.
639640
}
640641
----
641642

643+
[NOTE]
644+
The emit function for {ref}/geo-point.html[geo-point] fields takes two parameters ordered with
645+
`lat` before `lon`, but the output GeoJSON format orders the `coordinates` as `[ lon, lat ]`.
646+
642647
[[painless-runtime-ip]]
643648
===== `ip_field`
644649
The `ip_field` context is useful for data that includes IP addresses of type

docs/reference/mapping/types/geo-point.asciidoc

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Fields of type `geo_point` accept latitude-longitude pairs, which can be used:
1414
* to integrate distance into a document's <<query-dsl-function-score-query,relevance score>>.
1515
* to <<geo-sorting,sort>> documents by distance.
1616

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:
1818

1919
[source,console]
2020
--------------------------------------------------
@@ -31,7 +31,7 @@ PUT my-index-000001
3131
3232
PUT my-index-000001/_doc/1
3333
{
34-
"text": "Geopoint as an object",
34+
"text": "Geopoint as an object with 'lat' and 'lon' keys",
3535
"location": { <1>
3636
"lat": 41.12,
3737
"lon": -71.34
@@ -40,32 +40,41 @@ PUT my-index-000001/_doc/1
4040
4141
PUT my-index-000001/_doc/2
4242
{
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+
}
4548
}
4649
4750
PUT my-index-000001/_doc/3
4851
{
49-
"text": "Geopoint as a geohash",
50-
"location": "drm3btev3e86" <3>
52+
"text": "Geopoint as a string",
53+
"location": "41.12,-71.34" <3>
5154
}
5255
5356
PUT my-index-000001/_doc/4
5457
{
55-
"text": "Geopoint as an array",
56-
"location": [ -71.34, 41.12 ] <4>
58+
"text": "Geopoint as a geohash",
59+
"location": "drm3btev3e86" <4>
5760
}
5861
5962
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
6069
{
6170
"text": "Geopoint as a WKT POINT primitive",
62-
"location" : "POINT (-71.34 41.12)" <5>
71+
"location" : "POINT (-71.34 41.12)" <6>
6372
}
6473
6574
GET my-index-000001/_search
6675
{
6776
"query": {
68-
"geo_bounding_box": { <6>
77+
"geo_bounding_box": { <7>
6978
"location": {
7079
"top_left": {
7180
"lat": 42,
@@ -82,22 +91,26 @@ GET my-index-000001/_search
8291
--------------------------------------------------
8392

8493
<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]
8999
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.
91101

92102
[IMPORTANT]
93103
.Geopoints expressed as an array or string
94104
==================================================
95105
96106
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`.
98108
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`.
101114
102115
==================================================
103116

docs/reference/mapping/types/point.asciidoc

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ coordinate system.
1212
You can query documents using this type using
1313
<<query-dsl-shape-query,shape Query>>.
1414

15-
There are four ways that a point may be specified, as demonstrated below:
15+
There are five ways that a point may be specified, as demonstrated below:
1616

1717
[source,console]
1818
--------------------------------------------------
@@ -29,40 +29,53 @@ PUT my-index-000001
2929
3030
PUT my-index-000001/_doc/1
3131
{
32-
"text": "Point as an object",
32+
"text": "Point as an object with 'x' and 'y' keys",
3333
"location": { <1>
34-
"x": 41.12,
35-
"y": -71.34
34+
"x": -71.34,
35+
"y": 41.12
3636
}
3737
}
3838
3939
PUT my-index-000001/_doc/2
4040
{
41-
"text": "Point as a string",
42-
"location": "41.12,-71.34" <2>
41+
"text": "Point as an object using GeoJSON format",
42+
"location": { <2>
43+
"type": "Point",
44+
"coordinates": [-71.34, 41.12]
45+
}
4346
}
4447
48+
PUT my-index-000001/_doc/3
49+
{
50+
"text": "Point as a string",
51+
"location": "-71.34,41.12" <3>
52+
}
4553
4654
PUT my-index-000001/_doc/4
4755
{
4856
"text": "Point as an array",
49-
"location": [41.12, -71.34] <3>
57+
"location": [ -71.34, 41.12 ] <4>
5058
}
5159
5260
PUT my-index-000001/_doc/5
5361
{
5462
"text": "Point as a WKT POINT primitive",
55-
"location" : "POINT (41.12 -71.34)" <4>
63+
"location" : "POINT (-71.34 41.12)" <5>
5664
}
5765
5866
--------------------------------------------------
5967

6068
<1> Point expressed as an object, with `x` and `y` keys.
61-
<2> Point expressed as a string with the format: `"x,y"`.
62-
<3> Point expressed as an array with the format: [ `x`, `y`]
63-
<4> Point expressed as a https://docs.opengeospatial.org/is/12-063r5/12-063r5.html[Well-Known Text]
69+
<2> Point expressed as an object, in https://geojson.org/[GeoJSON] format, with `type` and `coordinates` keys.
70+
<3> Point expressed as a string with the format: `"x,y"`.
71+
<4> Point expressed as an array with the format: [ `x`, `y`]
72+
<5> Point expressed as a https://docs.opengeospatial.org/is/12-063r5/12-063r5.html[Well-Known Text]
6473
POINT with the format: `"POINT(x y)"`
6574

75+
[NOTE]
76+
Unlike the case with the {ref}/geo-point.html[geo-point] field type,
77+
the order of the coordinates `x` and `y` is the same for all formats above.
78+
6679
The coordinates provided to the indexer are single precision floating point values so
6780
the field guarantees the same accuracy provided by the java virtual machine (typically
6881
`1E-38`).

0 commit comments

Comments
 (0)