- Elasticsearch Guide: other versions:
- Getting Started
- Setup
- Breaking changes
- API Conventions
- Document APIs
- Search APIs
- Search
- URI Search
- Request Body Search
- Search Template
- Search Shards API
- Aggregations
- Min Aggregation
- Max Aggregation
- Sum Aggregation
- Avg Aggregation
- Stats Aggregation
- Extended Stats Aggregation
- Value Count Aggregation
- Percentiles Aggregation
- Percentile Ranks Aggregation
- Cardinality Aggregation
- Geo Bounds Aggregation
- Top hits Aggregation
- Scripted Metric Aggregation
- Global Aggregation
- Filter Aggregation
- Filters Aggregation
- Missing Aggregation
- Nested Aggregation
- Reverse nested Aggregation
- Children Aggregation
- Terms Aggregation
- Significant Terms Aggregation
- Range Aggregation
- Date Range Aggregation
- IPv4 Range Aggregation
- Histogram Aggregation
- Date Histogram Aggregation
- Geo Distance Aggregation
- GeoHash grid Aggregation
- Facets
- Suggesters
- Multi Search API
- Count API
- Search Exists API
- Validate API
- Explain API
- Percolator
- More Like This API
- Field stats API
- Indices APIs
- Create Index
- Delete Index
- Get Index
- Indices Exists
- Open / Close Index API
- Put Mapping
- Get Mapping
- Get Field Mapping
- Types Exists
- Delete Mapping
- Index Aliases
- Update Indices Settings
- Get Settings
- Analyze
- Index Templates
- Warmers
- Status
- Indices Stats
- Indices Segments
- Indices Recovery
- Clear Cache
- Flush
- Refresh
- Optimize
- Shadow replica indices
- Upgrade
- cat APIs
- Cluster APIs
- Query DSL
- Queries
- Match Query
- Multi Match Query
- Bool Query
- Boosting Query
- Common Terms Query
- Constant Score Query
- Dis Max Query
- Filtered Query
- Fuzzy Like This Query
- Fuzzy Like This Field Query
- Function Score Query
- Fuzzy Query
- GeoShape Query
- Has Child Query
- Has Parent Query
- Ids Query
- Indices Query
- Match All Query
- More Like This Query
- Nested Query
- Prefix Query
- Query String Query
- Simple Query String Query
- Range Query
- Regexp Query
- Span First Query
- Span Multi Term Query
- Span Near Query
- Span Not Query
- Span Or Query
- Span Term Query
- Term Query
- Terms Query
- Top Children Query
- Wildcard Query
- Minimum Should Match
- Multi Term Query Rewrite
- Template Query
- Filters
- And Filter
- Bool Filter
- Exists Filter
- Geo Bounding Box Filter
- Geo Distance Filter
- Geo Distance Range Filter
- Geo Polygon Filter
- GeoShape Filter
- Geohash Cell Filter
- Has Child Filter
- Has Parent Filter
- Ids Filter
- Indices Filter
- Limit Filter
- Match All Filter
- Missing Filter
- Nested Filter
- Not Filter
- Or Filter
- Prefix Filter
- Query Filter
- Range Filter
- Regexp Filter
- Script Filter
- Term Filter
- Terms Filter
- Type Filter
- Queries
- Mapping
- Analysis
- Analyzers
- Tokenizers
- Token Filters
- Standard Token Filter
- ASCII Folding Token Filter
- Length Token Filter
- Lowercase Token Filter
- Uppercase Token Filter
- NGram Token Filter
- Edge NGram Token Filter
- Porter Stem Token Filter
- Shingle Token Filter
- Stop Token Filter
- Word Delimiter Token Filter
- Stemmer Token Filter
- Stemmer Override Token Filter
- Keyword Marker Token Filter
- Keyword Repeat Token Filter
- KStem Token Filter
- Snowball Token Filter
- Phonetic Token Filter
- Synonym Token Filter
- Compound Word Token Filter
- Reverse Token Filter
- Elision Token Filter
- Truncate Token Filter
- Unique Token Filter
- Pattern Capture Token Filter
- Pattern Replace Token Filter
- Trim Token Filter
- Limit Token Count Token Filter
- Hunspell Token Filter
- Common Grams Token Filter
- Normalization Token Filter
- CJK Width Token Filter
- CJK Bigram Token Filter
- Delimited Payload Token Filter
- Keep Words Token Filter
- Keep Types Token Filter
- Classic Token Filter
- Apostrophe Token Filter
- Character Filters
- ICU Analysis Plugin
- Modules
- Index Modules
- Testing
- Glossary of terms
WARNING: Version 1.7 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Geo Point Type
editGeo Point Type
editMapper type called geo_point
to support geo based points. The
declaration looks as follows:
{ "pin" : { "properties" : { "location" : { "type" : "geo_point" } } } }
Indexed Fields
editThe geo_point
mapping will index a single field with the format of
lat,lon
. The lat_lon
option can be set to also index the .lat
and
.lon
as numeric fields, and geohash
can be set to true
to also
index .geohash
value.
A good practice is to enable indexing lat_lon
as well, since both the
geo distance and bounding box filters can either be executed using in
memory checks, or using the indexed lat lon values, and it really
depends on the data set which one performs better. Note though, that
indexed lat lon only make sense when there is a single geo point value
for the field, and not multi values.
Geohashes
editGeohashes are a form of lat/lon encoding which divides the earth up into a grid. Each cell in this grid is represented by a geohash string. Each cell in turn can be further subdivided into smaller cells which are represented by a longer string. So the longer the geohash, the smaller (and thus more accurate) the cell is.
Because geohashes are just strings, they can be stored in an inverted index like any other string, which makes querying them very efficient.
If you enable the geohash
option, a geohash
“sub-field” will be
indexed as, eg pin.geohash
. The length of the geohash is controlled by
the geohash_precision
parameter, which can either be set to an absolute
length (eg 12
, the default) or to a distance (eg 1km
).
More usefully, set the geohash_prefix
option to true
to not only index
the geohash value, but all the enclosing cells as well. For instance, a
geohash of u30
will be indexed as [u,u3,u30]
. This option can be used
by the Geohash Cell Filter to find geopoints within a
particular cell very efficiently.
Input Structure
editThe above mapping defines a geo_point
, which accepts different
formats. The following formats are supported:
Lat Lon as Properties
edit{ "pin" : { "location" : { "lat" : 41.12, "lon" : -71.34 } } }
Lat Lon as String
editFormat in lat,lon
.
{ "pin" : { "location" : "41.12,-71.34" } }
Geohash
edit{ "pin" : { "location" : "drm3btev3e86" } }
Lat Lon as Array
editFormat in [lon, lat]
, note, the order of lon/lat here in order to
conform with GeoJSON.
{ "pin" : { "location" : [-71.34, 41.12] } }
Mapping Options
editOption | Description |
---|---|
|
Set to |
|
Set to |
|
Sets the geohash precision. It can be set to an absolute geohash length or a distance value (eg 1km, 1m, 1ml) defining the size of the smallest cell. Defaults to an absolute length of 12. |
|
If this option is set to |
|
Set to |
|
Set to |
|
Set to |
|
Set to |
|
Set to |
|
Set to |
|
The precision step (influences the number of terms
generated for each number value) for |
Field data
editBy default, geo points use the array
format which loads geo points into two
parallel double arrays, making sure there is no precision loss. However, this
can require a non-negligible amount of memory (16 bytes per document) which is
why Elasticsearch also provides a field data implementation with lossy
compression called compressed
:
{ "pin" : { "properties" : { "location" : { "type" : "geo_point", "fielddata" : { "format" : "compressed", "precision" : "1cm" } } } } }
This field data format comes with a precision
option which allows to
configure how much precision can be traded for memory. The default value is
1cm
. The following table presents values of the memory savings given various
precisions:
Precision |
Bytes per point |
Size reduction |
1km |
4 |
75% |
3m |
6 |
62.5% |
1cm |
8 |
50% |
1mm |
10 |
37.5% |
Precision can be changed on a live index by using the update mapping API.
Usage in Scripts
editWhen using doc[geo_field_name]
(in the above mapping,
doc['location']
), the doc[...].value
returns a GeoPoint
, which
then allows access to lat
and lon
(for example,
doc[...].value.lat
). For performance, it is better to access the lat
and lon
directly using doc[...].lat
and doc[...].lon
.
On this page