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

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.4/query-dsl-geo-polygon-query.html#_lat_lon_as_string_4

译文链接 :Geo Polygon Query(地理多边形查询)

贡献者 : @yangbinApacheCNApache中文网

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

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}
                        ]
                    }
                }
            }
        }
    }
}

1.1.1. Query Options(查询选项)

Option(选项) Description(描述)
_name(名称) 可选名称字段来标识过滤器
ignore_malformed(忽略格式错误) [5.0.0] 设置为 true 以接受无效纬度或经度的地理点(默认值为假)。
validation_method(验证方法) 设置为 IGNORE_MALFORMED 以接受无效纬度或经度的地理点,COERCE 尝试推断正确的纬度或经度,或 STRICT(默认为 STRICT)。

1.1.2. Allowed Formats(允许格式)

1.1.3. 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]
                        ]
                    }
                }
            }
        }
    }
}

1.1.4. 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"
                        ]
                    }
                }
            }
        }
    }
}

1.1.5. Geohash(地理散列)

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

1.1.6. geo_point Type(geo_point类型)

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

1.1.7. Ignore Unmapped(忽略未映射)

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

Copyright © Kilvn 2021. all right reserved,powered by Gitbook最后更新时间: 2021-06-08 20:22:42

results matching ""

    No results matching ""