2015-05-05 02:27:52 -04:00
|
|
|
[[query-dsl-geo-bounding-box-query]]
|
|
|
|
== Geo Bounding Box Query
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-05-05 02:27:52 -04:00
|
|
|
A query allowing to filter hits based on a point location using a
|
2013-08-28 19:24:34 -04:00
|
|
|
bounding box. Assuming the following indexed document:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"pin" : {
|
|
|
|
"location" : {
|
|
|
|
"lat" : 40.12,
|
|
|
|
"lon" : -71.34
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
Then the following simple query can be executed with a
|
|
|
|
`geo_bounding_box` filter:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"filtered" : {
|
|
|
|
"query" : {
|
|
|
|
"match_all" : {}
|
|
|
|
},
|
|
|
|
"filter" : {
|
|
|
|
"geo_bounding_box" : {
|
|
|
|
"pin.location" : {
|
|
|
|
"top_left" : {
|
|
|
|
"lat" : 40.73,
|
|
|
|
"lon" : -74.1
|
|
|
|
},
|
|
|
|
"bottom_right" : {
|
|
|
|
"lat" : 40.01,
|
|
|
|
"lon" : -71.12
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
[float]
|
2015-05-05 02:27:52 -04:00
|
|
|
=== Accepted Formats
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
In much the same way the geo_point type can accept different
|
|
|
|
representation of the geo point, the filter can accept it as well:
|
|
|
|
|
|
|
|
[float]
|
2015-05-05 02:27:52 -04:00
|
|
|
==== Lat Lon As Properties
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"filtered" : {
|
|
|
|
"query" : {
|
|
|
|
"match_all" : {}
|
|
|
|
},
|
|
|
|
"filter" : {
|
|
|
|
"geo_bounding_box" : {
|
|
|
|
"pin.location" : {
|
|
|
|
"top_left" : {
|
|
|
|
"lat" : 40.73,
|
|
|
|
"lon" : -74.1
|
|
|
|
},
|
|
|
|
"bottom_right" : {
|
|
|
|
"lat" : 40.01,
|
|
|
|
"lon" : -71.12
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
[float]
|
2015-05-05 02:27:52 -04:00
|
|
|
==== Lat Lon As Array
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
Format in `[lon, lat]`, note, the order of lon/lat here in order to
|
|
|
|
conform with http://geojson.org/[GeoJSON].
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"filtered" : {
|
|
|
|
"query" : {
|
|
|
|
"match_all" : {}
|
|
|
|
},
|
|
|
|
"filter" : {
|
|
|
|
"geo_bounding_box" : {
|
|
|
|
"pin.location" : {
|
|
|
|
"top_left" : [-74.1, 40.73],
|
|
|
|
"bottom_right" : [-71.12, 40.01]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
[float]
|
2015-05-05 02:27:52 -04:00
|
|
|
==== Lat Lon As String
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
Format in `lat,lon`.
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"filtered" : {
|
|
|
|
"query" : {
|
|
|
|
"match_all" : {}
|
|
|
|
},
|
|
|
|
"filter" : {
|
|
|
|
"geo_bounding_box" : {
|
|
|
|
"pin.location" : {
|
|
|
|
"top_left" : "40.73, -74.1",
|
|
|
|
"bottom_right" : "40.01, -71.12"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
[float]
|
2015-05-05 02:27:52 -04:00
|
|
|
==== Geohash
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"filtered" : {
|
|
|
|
"query" : {
|
|
|
|
"match_all" : {}
|
|
|
|
},
|
|
|
|
"filter" : {
|
|
|
|
"geo_bounding_box" : {
|
|
|
|
"pin.location" : {
|
|
|
|
"top_left" : "dr5r9ydj2y73",
|
|
|
|
"bottom_right" : "drj7teegpus6"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2013-12-18 23:52:33 -05:00
|
|
|
[float]
|
2015-05-05 02:27:52 -04:00
|
|
|
=== Vertices
|
2013-12-18 23:52:33 -05:00
|
|
|
|
|
|
|
The 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.
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"filtered" : {
|
|
|
|
"query" : {
|
|
|
|
"match_all" : {}
|
|
|
|
},
|
|
|
|
"filter" : {
|
|
|
|
"geo_bounding_box" : {
|
|
|
|
"pin.location" : {
|
|
|
|
"top" : -74.1,
|
|
|
|
"left" : 40.73,
|
|
|
|
"bottom" : -71.12,
|
|
|
|
"right" : 40.01
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
[float]
|
2015-05-05 02:27:52 -04:00
|
|
|
=== geo_point Type
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
The filter *requires* the `geo_point` type to be set on the relevant
|
|
|
|
field.
|
|
|
|
|
|
|
|
[float]
|
2015-05-05 02:27:52 -04:00
|
|
|
=== Multi Location Per Document
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
The 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
|
|
|
|
|
|
|
|
[float]
|
2015-05-05 02:27:52 -04:00
|
|
|
=== Type
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
The 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:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"filtered" : {
|
|
|
|
"query" : {
|
|
|
|
"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"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|