GeoShape Query(地理形状查询)
过滤文档索引使用geo_shape型。
需要geo_shape映射。
geo_shape查询使用相同的网格表示为geo_shape映射到有相交形状文档的查询。它也可使用相同的PrefixTree配置为域的映射定义。 该查询支持两种定义查询形状的方法,或者通过提供一个整体形状定义,或者通过引用另一个索引中的形状的名称引用该形状的名称。这两种格式在下面的例子中都有解释。
Inline Shape Definition(内联形状定义)
和geo_shape类型类似,geo_shape的过滤器使用GeoJSON来描述形状。
下面是一个例子,就像这样:
PUT /example
{
"mappings": {
"doc": {
"properties": {
"location": {
"type": "geo_shape"
}
}
}
}
}
POST /example/doc?refresh
{
"name": "Wind & Wetter, Berlin, Germany",
"location": {
"type": "point",
"coordinates": [13.400544, 52.530286]
}
}
下面的查询将使用Elasticsearch封装的GeoJSON扩展寻找点:
GET /example/_search
{
"query":{
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_shape": {
"location": {
"shape": {
"type": "envelope",
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
},
"relation": "within"
}
}
}
}
}
}
Pre-Indexed Shape(预索引形状)
该查询还支持使用已在另一个索引和/或索引类型中已被索引的形状。当你有一个预先定义好的形状列表,这个形状列表用于你的应用程序和你参考使用的一个逻辑名称(例如新西兰),而不是每一次都必须提供他的坐标。在这种情况下,只需要提供:
id
- 包含预索引形状的文档ID。index
- 索引的名称,其中预索引形状为:默认形状。type
- 索引类型,预索引形状的类。path
- 包含预索引形状的指定路径,默认形状。
下面是一个使用了预索引形状过滤的例子:
PUT /shapes
{
"mappings": {
"doc": {
"properties": {
"location": {
"type": "geo_shape"
}
}
}
}
}
PUT /shapes/doc/deu
{
"location": {
"type": "envelope",
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
}
}
GET /example/_search
{
"query": {
"bool": {
"filter": {
"geo_shape": {
"location": {
"indexed_shape": {
"index": "shapes",
"type": "doc",
"id": "deu",
"path": "location"
}
}
}
}
}
}
}
Spatial Relations(空间关系)
geo_shape策略映射参数确定的空间关系操作符可以用于搜索的时间。以下是可用的空间关系操作符的完整列表:
INTERSECTS
- (默认)返回所有文件的geo_shape场相交查询几何。DISJOINT
- Return all documents whose geo_shape field has nothing in common with the query geometry.WITHIN
- 返回geo_shape字段查询内几何的所有文档。CONTAINS
- 返回的geo_shape字段包含查询几何的所有文件。
Ignore Unmapped(忽略映射)
当设置ignore_unmapped选项为true时,将忽略未映射字段,并且该查询将不匹配任何文档。这在当查询可能有不同映射的多索引时是有用的。当设置为false(默认值为false)时,如果字段没有映射,那这个查询将会抛出异常。
Last updated
Was this helpful?