Geo Polygon Query(地理多边形查询)

一个查询,允许包含仅在点的多边形内的命中。 这是一个例子:

GET /_search
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_polygon" : {
                    "person.location" : {
                        "points" : [
                        {"lat" : 40, "lon" : -70},
                        {"lat" : 30, "lon" : -80},
                        {"lat" : 20, "lon" : -90}
                        ]
                    }
                }
            }
        }
    }
}

Query Options(查询选项)

Query Options(查询选项)

Option(选项)

Description(描述)

_name(名称)

可选名称字段来标识过滤器

ignore_malformed(忽略格式错误)

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

validation_method(验证方法)

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

Allowed Formats(允许格式)

Lat Long as Array(Lat Long 作为阵列)

格式在[lon,lat]中,注意,这里的lon / lat的顺序是为了符合 GeoJSON.

GET /_search
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_polygon" : {
                    "person.location" : {
                        "points" : [
                            [-70, 40],
                            [-80, 30],
                            [-90, 20]
                        ]
                    }
                }
            }
        }
    }
}

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

格式在 lat,lon。

GET /_search
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
               "geo_polygon" : {
                    "person.location" : {
                        "points" : [
                            "40, -70",
                            "30, -80",
                            "20, -90"
                        ]
                    }
                }
            }
        }
    }
}

Geohash(地理散列)

GET /_search
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
               "geo_polygon" : {
                    "person.location" : {
                        "points" : [
                            "drn5x1g8cu2y",
                            "30, -80",
                            "20, -90"
                        ]
                    }
                }
            }
        }
    }
}

geo_point Type(geo_point类型)

该查询需要在相关字段上设置geo_point 类型。

Ignore Unmapped(忽略未映射)

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

Last updated