# 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**）时，如果字段没有映射，那这个查询将会抛出异常。


---

# 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/geoshape-querydi-li-xing-zhuang-cha-8be229.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.
