- Elasticsearch Guide: other versions:
- Getting Started
- Setup
- Breaking changes
- Breaking changes in 2.0
- Removed features
- Network changes
- Multiple
path.data
striping - Mapping changes
- CRUD and routing changes
- Query DSL changes
- Search changes
- Aggregation changes
- Parent/Child changes
- Scripting changes
- Index API changes
- Snapshot and Restore changes
- Plugin and packaging changes
- Setting changes
- Stats, info, and
cat
changes - Java API changes
- Breaking changes in 2.0
- API Conventions
- Document APIs
- Search APIs
- Aggregations
- Metrics Aggregations
- Bucket Aggregations
- Children Aggregation
- Date Histogram Aggregation
- Date Range Aggregation
- Filter Aggregation
- Filters Aggregation
- Geo Distance Aggregation
- GeoHash grid Aggregation
- Global Aggregation
- Histogram Aggregation
- IPv4 Range Aggregation
- Missing Aggregation
- Nested Aggregation
- Range Aggregation
- Reverse nested Aggregation
- Sampler Aggregation
- Significant Terms Aggregation
- Terms Aggregation
- Pipeline Aggregations
- Caching heavy aggregations
- Returning only aggregation results
- Aggregation Metadata
- Indices APIs
- Create Index
- Delete Index
- Get Index
- Indices Exists
- Open / Close Index API
- Put Mapping
- Get Mapping
- Get Field Mapping
- Types Exists
- Index Aliases
- Update Indices Settings
- Get Settings
- Analyze
- Index Templates
- Warmers
- Shadow replica indices
- Indices Stats
- Indices Segments
- Indices Recovery
- Indices Shard Stores
- Clear Cache
- Flush
- Refresh
- Optimize
- Upgrade
- cat APIs
- Cluster APIs
- Query DSL
- Mapping
- Field datatypes
- Meta-Fields
- Mapping parameters
analyzer
boost
coerce
copy_to
doc_values
dynamic
enabled
fielddata
format
geohash
geohash_precision
geohash_prefix
ignore_above
ignore_malformed
include_in_all
index
index_options
lat_lon
fields
norms
null_value
position_increment_gap
precision_step
properties
search_analyzer
similarity
store
term_vector
- Dynamic Mapping
- Transform
- 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
- Release Notes
WARNING: Version 2.0 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 Bounding Box Query
editGeo Bounding Box Query
editA query allowing to filter hits based on a point location using a bounding box. Assuming the following indexed document:
{ "pin" : { "location" : { "lat" : 40.12, "lon" : -71.34 } } }
Then the following simple query can be executed with a
geo_bounding_box
filter:
{ "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_bounding_box" : { "pin.location" : { "top_left" : { "lat" : 40.73, "lon" : -74.1 }, "bottom_right" : { "lat" : 40.01, "lon" : -71.12 } } } } } }
Query Options
editOption | Description |
---|---|
|
Optional name field to identify the filter |
|
Set to |
|
Set to |
|
Set to one of |
Accepted Formats
editIn much the same way the geo_point type can accept different representation of the geo point, the filter can accept it as well:
Lat Lon As Properties
edit{ "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_bounding_box" : { "pin.location" : { "top_left" : { "lat" : 40.73, "lon" : -74.1 }, "bottom_right" : { "lat" : 40.01, "lon" : -71.12 } } } } } }
Lat Lon As Array
editFormat in [lon, lat]
, note, the order of lon/lat here in order to
conform with GeoJSON.
{ "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_bounding_box" : { "pin.location" : { "top_left" : [-74.1, 40.73], "bottom_right" : [-71.12, 40.01] } } } } }
Lat Lon As String
editFormat in lat,lon
.
{ "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_bounding_box" : { "pin.location" : { "top_left" : "40.73, -74.1", "bottom_right" : "40.01, -71.12" } } } } }
Geohash
edit{ "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_bounding_box" : { "pin.location" : { "top_left" : "dr5r9ydj2y73", "bottom_right" : "drj7teegpus6" } } } } }
Vertices
editThe vertices of the bounding box can either be set by top_left
and
bottom_right
or by top_right
and bottom_left
parameters. More
over the names topLeft
, bottomRight
, topRight
and bottomLeft
are supported. Instead of setting the values pairwise, one can use
the simple names top
, left
, bottom
and right
to set the
values separately.
{ "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_bounding_box" : { "pin.location" : { "top" : -74.1, "left" : 40.73, "bottom" : -71.12, "right" : 40.01 } } } } }
geo_point Type
editThe filter requires the geo_point
type to be set on the relevant
field.
Multi Location Per Document
editThe filter can work with multiple locations / points per document. Once a single location / point matches the filter, the document will be included in the filter
Type
editThe type of the bounding box execution by default is set to memory
,
which means in memory checks if the doc falls within the bounding box
range. In some cases, an indexed
option will perform faster (but note
that the geo_point
type must have lat and lon indexed in this case).
Note, when using the indexed option, multi locations per document field
are not supported. Here is an example:
{ "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_bounding_box" : { "pin.location" : { "top_left" : { "lat" : 40.73, "lon" : -74.1 }, "bottom_right" : { "lat" : 40.10, "lon" : -71.12 } }, "type" : "indexed" } } } }
On this page