OpenSearch/docs/reference/query-dsl/geo-bounding-box-query.asci...

253 lines
6.3 KiB
Plaintext
Raw Normal View History

[[query-dsl-geo-bounding-box-query]]
=== Geo Bounding Box Query
A query allowing to filter hits based on a point location using a
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]
==== Query Options
[cols="<,<",options="header",]
|=======================================================================
|Option |Description
|`_name` |Optional name field to identify the filter
|`coerce` |Set to `true` to normalize longitude and latitude values to a
standard -180:180 / -90:90 coordinate system. (default is `false`).
|`ignore_malformed` |Set to `true` to
accept geo points with invalid latitude or longitude (default is `false`).
|`type` |Set to one of `indexed` or `memory` to defines whether this filter will
2015-08-18 06:20:00 -04:00
be executed in memory or indexed. See <<geo-bbox-type,Type>> below for further details
Default is `memory`.
|=======================================================================
[float]
==== Accepted Formats
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]
===== Lat Lon As Properties
[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]
===== Lat Lon As Array
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]
===== Lat Lon As String
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]
===== Geohash
[source,js]
--------------------------------------------------
{
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_bounding_box" : {
"pin.location" : {
"top_left" : "dr5r9ydj2y73",
"bottom_right" : "drj7teegpus6"
}
}
}
}
}
--------------------------------------------------
Geo clean Up ============ The default unit for measuring distances is *MILES* in most cases. This commit moves ES over to the *International System of Units* and make it work on a default which relates to *METERS* . Also the current structures of the `GeoBoundingBox Filter` changed in order to define the *Bounding* by setting abitrary corners. Distances --------- Since the default unit for measuring distances has changed to a default unit `DistanceUnit.DEFAULT` relating to *meters*, the **REST API** has changed at the following places: * `ScriptDocValues.factorDistance()` returns *meters* instead of *miles* * `ScriptDocValues.factorDistanceWithDefault()` returns *meters* instead of *miles* * `ScriptDocValues.arcDistance()` returns *meters* instead of *miles* one might use `ScriptDocValues.arcDistanceInMiles()` * `ScriptDocValues.arcDistanceWithDefault()` returns *meters* instead of *miles* * `ScriptDocValues.distance()` returns *meters* instead of *miles* one might use `ScriptDocValues.distanceInMiles()` * `ScriptDocValues.distanceWithDefault()` returns *meters* instead of *miles* one might use `ScriptDocValues.distanceInMilesWithDefault()` * `GeoDistanceFilter` default unit changes from *kilometers* to *meters* * `GeoDistanceRangeFilter` default unit changes from *miles* to *meters* * `GeoDistanceFacet` default unit changes from *miles* to *meters* Geo Bounding Box Filter ----------------------- The naming of the GeoBoundingBoxFilter properties allows to set arbitrary corners (see #4084) namely `top_right`, `top_left`, `bottom_right` and `bottom_left`. This change also includes the fields `topRight` and `bottomLeft` Also it is be possible to set the single values by using just `top`, `bottom`, `left` and `right` parameters. Closes #4515, #4084
2013-12-18 23:52:33 -05:00
[float]
==== Vertices
Geo clean Up ============ The default unit for measuring distances is *MILES* in most cases. This commit moves ES over to the *International System of Units* and make it work on a default which relates to *METERS* . Also the current structures of the `GeoBoundingBox Filter` changed in order to define the *Bounding* by setting abitrary corners. Distances --------- Since the default unit for measuring distances has changed to a default unit `DistanceUnit.DEFAULT` relating to *meters*, the **REST API** has changed at the following places: * `ScriptDocValues.factorDistance()` returns *meters* instead of *miles* * `ScriptDocValues.factorDistanceWithDefault()` returns *meters* instead of *miles* * `ScriptDocValues.arcDistance()` returns *meters* instead of *miles* one might use `ScriptDocValues.arcDistanceInMiles()` * `ScriptDocValues.arcDistanceWithDefault()` returns *meters* instead of *miles* * `ScriptDocValues.distance()` returns *meters* instead of *miles* one might use `ScriptDocValues.distanceInMiles()` * `ScriptDocValues.distanceWithDefault()` returns *meters* instead of *miles* one might use `ScriptDocValues.distanceInMilesWithDefault()` * `GeoDistanceFilter` default unit changes from *kilometers* to *meters* * `GeoDistanceRangeFilter` default unit changes from *miles* to *meters* * `GeoDistanceFacet` default unit changes from *miles* to *meters* Geo Bounding Box Filter ----------------------- The naming of the GeoBoundingBoxFilter properties allows to set arbitrary corners (see #4084) namely `top_right`, `top_left`, `bottom_right` and `bottom_left`. This change also includes the fields `topRight` and `bottomLeft` Also it is be possible to set the single values by using just `top`, `bottom`, `left` and `right` parameters. Closes #4515, #4084
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
}
}
}
}
}
--------------------------------------------------
[float]
==== geo_point Type
The filter *requires* the `geo_point` type to be set on the relevant
field.
[float]
==== Multi Location Per Document
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-08-18 06:20:00 -04:00
[[geo-bbox-type]]
==== Type
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"
}
}
}
}
--------------------------------------------------