mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-06 04:58:50 +00:00
c595322d90
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)
138 lines
3.2 KiB
Plaintext
138 lines
3.2 KiB
Plaintext
[[query-dsl-geo-polygon-query]]
|
|
=== Geo Polygon Query
|
|
|
|
A query allowing to include hits that only fall within a polygon of
|
|
points. Here is an example:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
{
|
|
"bool" : {
|
|
"query" : {
|
|
"match_all" : {}
|
|
},
|
|
"filter" : {
|
|
"geo_polygon" : {
|
|
"person.location" : {
|
|
"points" : [
|
|
{"lat" : 40, "lon" : -70},
|
|
{"lat" : 30, "lon" : -80},
|
|
{"lat" : 20, "lon" : -90}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
[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`).
|
|
|=======================================================================
|
|
|
|
[float]
|
|
==== Allowed Formats
|
|
|
|
[float]
|
|
===== Lat Long 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_polygon" : {
|
|
"person.location" : {
|
|
"points" : [
|
|
[-70, 40],
|
|
[-80, 30],
|
|
[-90, 20]
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
[float]
|
|
===== Lat Lon as String
|
|
|
|
Format in `lat,lon`.
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
{
|
|
"bool" : {
|
|
"must" : {
|
|
"match_all" : {}
|
|
},
|
|
"filter" : {
|
|
"geo_polygon" : {
|
|
"person.location" : {
|
|
"points" : [
|
|
"40, -70",
|
|
"30, -80",
|
|
"20, -90"
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
[float]
|
|
===== Geohash
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
{
|
|
"bool" : {
|
|
"must" : {
|
|
"match_all" : {}
|
|
},
|
|
"filter" : {
|
|
"geo_polygon" : {
|
|
"person.location" : {
|
|
"points" : [
|
|
"drn5x1g8cu2y",
|
|
"30, -80",
|
|
"20, -90"
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
[float]
|
|
==== geo_point Type
|
|
|
|
The query *requires* the <<geo-point,`geo_point`>> type to be set on the
|
|
relevant field.
|
|
|
|
[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.
|