mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-03 09:29:11 +00:00
The change adds a new option to the geo_* queries: ignore_unmapped. If this option is set to false, the toQuery method on the QueryBuilder will throw an exception if the field specified in the query is unmapped. If the option is set to true, the toQuery method on the QueryBuilder will return a MatchNoDocsQuery. The default value is false so the queries work how they do today (throwing an exception on unmapped field)
258 lines
6.4 KiB
Plaintext
258 lines
6.4 KiB
Plaintext
[[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]
|
|
--------------------------------------------------
|
|
{
|
|
"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
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
[float]
|
|
==== Query Options
|
|
|
|
[cols="<,<",options="header",]
|
|
|=======================================================================
|
|
|Option |Description
|
|
|`_name` |Optional name field to identify the filter
|
|
|
|
|`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
|
|
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]
|
|
--------------------------------------------------
|
|
{
|
|
"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
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
[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]
|
|
--------------------------------------------------
|
|
{
|
|
"bool" : {
|
|
"must" : {
|
|
"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]
|
|
--------------------------------------------------
|
|
{
|
|
"bool" : {
|
|
"must" : {
|
|
"match_all" : {}
|
|
},
|
|
"filter" : {
|
|
"geo_bounding_box" : {
|
|
"pin.location" : {
|
|
"top_left" : "40.73, -74.1",
|
|
"bottom_right" : "40.01, -71.12"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
[float]
|
|
===== Geohash
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
{
|
|
"bool" : {
|
|
"must" : {
|
|
"match_all" : {}
|
|
},
|
|
"filter" : {
|
|
"geo_bounding_box" : {
|
|
"pin.location" : {
|
|
"top_left" : "dr5r9ydj2y73",
|
|
"bottom_right" : "drj7teegpus6"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
[float]
|
|
==== Vertices
|
|
|
|
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]
|
|
--------------------------------------------------
|
|
{
|
|
"bool" : {
|
|
"must" : {
|
|
"match_all" : {}
|
|
},
|
|
"filter" : {
|
|
"geo_bounding_box" : {
|
|
"pin.location" : {
|
|
"top" : 40.73,
|
|
"left" : -74.1,
|
|
"bottom" : 40.01,
|
|
"right" : -71.12
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
|
|
[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]
|
|
[[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]
|
|
--------------------------------------------------
|
|
{
|
|
"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"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
[float]
|
|
==== Ignore Unmapped
|
|
|
|
When set to `true` the `ignore_unmapped` option will ignore an unmapped field
|
|
and will not match any documents for this query. This can be useful when
|
|
querying multiple indexes which might have different mappings. When set to
|
|
`false` (the default value) the query will throw an exception if the field
|
|
is not mapped.
|