Skip to content

Commit 48e9d48

Browse files
Made geo into its own part, and removed percolation
1 parent 96d859a commit 48e9d48

29 files changed

+238
-271
lines changed

310_Geolocation/10_Intro.asciidoc 04_Geolocation.asciidoc

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[[geoloc]]
2-
== Geolocation
2+
= Geolocation
33

4+
[partintro]
5+
--
46
Gone are the days when we wander around a city with paper maps. Thanks to
57
smartphones, we now know exactly where we are all of the time, and we expect
68
websites to use that information. I'm not interested in restaurants in
@@ -29,5 +31,6 @@ other hand, are used purely for filtering. They can be used to decide whether
2931
two shapes overlap or not, or whether one shape completely contains other
3032
shapes.
3133

34+
--
3235

3336

310_Geolocation.asciidoc

-56
This file was deleted.

310_Geolocation/40_Geohashes.asciidoc

-177
This file was deleted.

310_Geopoints.asciidoc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
include::310_Geopoints/20_Geopoints.asciidoc[]
2+
3+
include::310_Geopoints/30_Filter_by_geopoint.asciidoc[]
4+
5+
include::310_Geopoints/32_Bounding_box.asciidoc[]
6+
7+
include::310_Geopoints/34_Geo_distance.asciidoc[]
8+
9+
include::310_Geopoints/36_Caching_geofilters.asciidoc[]
10+
11+
include::310_Geopoints/38_Reducing_memory.asciidoc[]
12+
13+
include::310_Geopoints/50_Sorting_by_distance.asciidoc[]
14+

310_Geolocation/20_Geopoints.asciidoc 310_Geopoints/20_Geopoints.asciidoc

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
[[indexing-geopoints]]
2-
=== Indexing geo-points
1+
[[geopoints]]
2+
== Geo-points
3+
4+
A geo-point is a single latitude-longitude point on the Earth's surface. They
5+
can be used to calculate distance from a point, to determine whether a point
6+
falls within a bounding box, or in aggregations.
37

48
Geo-points cannot be automatically detected with
5-
<<dynamic-mapping,dynamic mapping>>. Instead, geo-points fields should be
9+
<<dynamic-mapping,dynamic mapping>>. Instead, `geo_point` fields should be
610
mapped explicitly:
711

812
[source,json]
@@ -25,7 +29,8 @@ PUT /attractions
2529
-----------------------
2630

2731
[[lat-lon-formats]]
28-
==== Lat/Lon formats
32+
[float]
33+
=== Lat/Lon formats
2934

3035
With the `location` field defined as a `geo_point`, we can proceed to index
3136
documents containing latitude/longitude pairs, which can be formatted as

320_Geohashes.asciidoc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include::320_Geohashes/40_Geohashes.asciidoc[]
2+
3+
include::320_Geohashes/50_Geohash_mapping.asciidoc[]
4+
5+
include::320_Geohashes/60_Geohash_cell_filter.asciidoc[]
6+

320_Geohashes/40_Geohashes.asciidoc

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[[geohashes]]
2+
== Geohashes
3+
4+
http://en.wikipedia.org/wiki/Geohash[Geohashes] are a way of encoding
5+
`lat/lon` points as strings. The original intention was to have a
6+
URL-friendly way of specifying geolocations, but geohashes have turned out to
7+
be a useful way of indexing geo-points and geo- shapes in databases.
8+
9+
Geohashes divide the world up into a grid of 32 cells -- 4 rows and 8 columns
10+
-- each represented by a letter or number. The `g` cell covers half of
11+
Greenland, all of Iceland and most of Great Britian. Each cell can be further
12+
divided into anokther 32 cells, which can be divided into another 32 cells,
13+
and so on. The `gc`, cell covers Ireland and England, `gcp` covers most of
14+
London and part of Southern England, and `gcpuuz94k` is the entrance to
15+
Buckingham Palace, accurate to about 5 metres.
16+
17+
In other words, the longer the geohash string, the more accurate it is. If
18+
two geohashes share a prefix -- `gcpuux` and `gcpuuz` -- then it implies that
19+
they are near to each other. The longer the shared prefix, the closer they
20+
are.
21+
22+
That said, two locations that are right next to each other may have completely
23+
different geohashes. For instance, the
24+
http://en.wikipedia.org/wiki/Millennium_Dome[Millenium Dome] in London has
25+
geohash `u10hbp`, because it falls into the `u` cell, the next top-level cell
26+
to the east of the `g` cell.
27+
28+
Geo-points can index their associated geohashes automatically, but more
29+
importantly, they can also index all geohash *prefixes*. Indexing the location
30+
of the entrance to Buckingham Palace -- latitude `51.501568` and longitude
31+
`-0.141257` -- would index all of the geohashes listed in the table below,
32+
along with the approximate dimensions of each geohash cell:
33+
34+
[cols="1m,1m,3d",options="header"]
35+
|=============================================
36+
|Geohash |Level| Dimensions
37+
|g |1 | ~ 5,004km x 5,004km
38+
|gc |2 | ~ 1,251km x 625km
39+
|gcp |3 | ~ 156km x 156km
40+
|gcpu |4 | ~ 39km x 19.5km
41+
|gcpuu |5 | ~ 4.9km x 4.9km
42+
|gcpuuz |6 | ~ 1.2km x 0.61km
43+
|gcpuuz9 |7 | ~ 152.8m x 152.8m
44+
|gcpuuz94 |8 | ~ 38.2m x 19.1m
45+
|gcpuuz94k |9 | ~ 4.78m x 4.78m
46+
|gcpuuz94kk |10 | ~ 1.19m x 0.60m
47+
|gcpuuz94kkp |11 | ~ 14.9cm x 14.9cm
48+
|gcpuuz94kkp5 |12 | ~ 3.7cm x 1.8cm
49+
|=============================================
50+
51+
The {ref}query-dsl-geohash-cell-filter.html[`geohash_cell` filter] can use
52+
these geohash prefixes to find locations near a specified `lat/lon` point.
53+
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[[geohash-mapping]]
2+
=== Mapping geohashes
3+
4+
The first step is to decide just how much precision you need. While you could
5+
index all geo-points with the default full 12 levels of precision, do you
6+
really need to be accurate to within a few centimeters? You can save yourself
7+
a lot of space in the index by reducing your precision requirements to
8+
something more realistic, such as `1km`.
9+
10+
[source,json]
11+
----------------------------
12+
PUT /attractions
13+
{
14+
"mappings": {
15+
"restaurant": {
16+
"properties": {
17+
"name": {
18+
"type": "string"
19+
},
20+
"location": {
21+
"type": "geo_point",
22+
"geohash_prefix": true, <1>
23+
"geohash_precision": "1km" <2>
24+
}
25+
}
26+
}
27+
}
28+
}
29+
----------------------------
30+
<1> Setting `geohash_prefix` to `true` tells Elasticsearch to index
31+
all geohash prefixes, up to the specified precision.
32+
<2> The precision can be specified as an absolute number, representing the
33+
length of the geohash, or as a distance. A precision of `1km` corresponds
34+
to a geohash of length `7`.
35+
36+
With this mapping in place, geohash prefixes of lengths 1 to 7 will be indexed,
37+
providing geohashes accuracate to about 150 meters.
38+

0 commit comments

Comments
 (0)