# 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（允许格式） <a href="#geopolygonquery-di-li-duo-bian-xing-cha-xun-allowedformats-yun-xu-ge-shi" id="geopolygonquery-di-li-duo-bian-xing-cha-xun-allowedformats-yun-xu-ge-shi"></a>

## Lat Long as Array（Lat Long 作为阵列） <a href="#geopolygonquery-di-li-duo-bian-xing-cha-xun-latlongasarraylatlong-zuo-wei-zhen-lie" id="geopolygonquery-di-li-duo-bian-xing-cha-xun-latlongasarraylatlong-zuo-wei-zhen-lie"></a>

格式&#x5728;**\[lon，lat]**&#x4E2D;，注意，这里的**lon / lat**的顺序是为了符合 [**GeoJSON**](http://geojson.org/)**.**&#x20;

```
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 作为字符串） <a href="#geopolygonquery-di-li-duo-bian-xing-cha-xun-latlonasstringlatlon-zuo-wei-zi-fu-chuan" id="geopolygonquery-di-li-duo-bian-xing-cha-xun-latlonasstringlatlon-zuo-wei-zi-fu-chuan"></a>

格式在 **lat，lon。**&#x20;

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

## Geohash（地理散列） <a href="#geopolygonquery-di-li-duo-bian-xing-cha-xun-geohash-di-li-san-lie" id="geopolygonquery-di-li-duo-bian-xing-cha-xun-geohash-di-li-san-lie"></a>

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

## geo\_point Type（geo\_point类型） <a href="#geopolygonquery-di-li-duo-bian-xing-cha-xun-geopointtypegeopoint-lei-xing" id="geopolygonquery-di-li-duo-bian-xing-cha-xun-geopointtypegeopoint-lei-xing"></a>

该查询需要在相关字段上设置[`geo_point`](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/geo-point.html) 类型。

## Ignore Unmapped（忽略未映射） <a href="#geopolygonquery-di-li-duo-bian-xing-cha-xun-ignoreunmapped-hu-lve-wei-ying-she" id="geopolygonquery-di-li-duo-bian-xing-cha-xun-ignoreunmapped-hu-lve-wei-ying-she"></a>

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaoxiami.gitbook.io/elasticsearch/ji-chu/35query-dsldslfang-shi-cha-8be229/357di-li-wei-zhi-cha-xun-geo-queries/geo-polygon-queryff08-di-li-duo-bian-xing-cha-xun-ff09.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
