Geo Distance Query(地理距离查询)

过滤仅包含距离地理位置特定距离内的命中的文档。 假设以下映射和索引文档:

PUT /my_locations
{
    "mappings": {
        "location": {
            "properties": {
                "pin": {
                    "properties": {
                        "location": {
                            "type": "geo_point"
                        }
                    }
                }
            }
        }
    }
}

PUT /my_locations/location/1
{
    "pin" : {
        "location" : {
            "lat" : 40.12,
            "lon" : -71.34
        }
    }
}

然后可以使用 geo_distance 过滤器执行以下简单查询:

Accepted Formats (接受格式)

以同样的方式,geo_point类型可以接受地理点的不同表示,过滤器也可以接受它:

Lat Lon As Properties (Lat Lon作为属性)

Lat Lon As Array (Lat Lon作为阵列)

Format in[lon, lat], note, the order of lon/lat here in order to conform with GeoJSON.

Lat Lon As String(Lat Lon作为字符串)

Format in lat,lon.

Geohash(地理散列)

Options(选项)

以下是过滤器上允许的选项:

distance(距离)

以指定位置为中心的圆的半径。 落入此圈子的点被认为是匹配的。 距离可以用各种单位指定。 看 the section called “Distance Unitsedit”.

distance_type(距离类型)

如何计算距离。 可以是弧(默认)或平面(更快,但长距离不准确,靠近极点)。

optimize_bbox(优化bbox)

是否在距离检查之前首先运行边框检查使用优化。 默认在内存检查中执行的内存。 也可以使用索引值来使用索引值检查(在这种情况下确保geo_pointtype索引lat lon),否则禁用边界框优化。[2.2]

_name(名称)

可选名称字段来标识查询。

ignore_malformed(忽略格式错误)

[5.0.0] 设置为true以接受无效纬度或经度的地理点(默认值为假)。

validation_method(验证方法)

设置为IGNORE_MALFORMED以接受无效纬度或经度的地理点,设置为COERCE以额外尝试推断正确的坐标(默认为STRICT)。

geo_point Type(geo_point类型)

过滤器需要在相关字段上设置geo_point类型。

Multi Location Per Document(每个文档的多个位置)

geo_distance过滤器可以处理每个文档的多个位置/点。 一旦单个位置/点与过滤器匹配,文档将被包含在过滤器中。

Ignore Unmapped(忽略未映射)

当设置为true时,ignore_unmapped 选项将忽略未映射字段,并且将不会匹配此查询的任何文档。 当查询可能具有不同映射的多个索引时,可能很有用。 当设置为false(默认值)时,如果字段未映射,则查询将抛出异常。

Last updated

Was this helpful?