<commit_before>[[query-dsl-geo-shape-filter]]
=== GeoShape Filter

Filter documents indexed using the `geo_shape` type.

Requires the <<mapping-geo-shape-type,geo_shape
Mapping>>.

You may also use the
<<query-dsl-geo-shape-query,geo_shape Query>>.

The `geo_shape` Filter uses the same grid square representation as the
geo_shape mapping to find documents that have a shape that intersects
with the query shape. It will also use the same PrefixTree configuration
as defined for the field mapping.

[float]
==== Filter Format

The Filter supports two ways of defining the Filter shape, either by
providing a whole shape defintion, or by referencing the name of a shape
pre-indexed in another index. Both formats are defined below with
examples.

[float]
===== Provided Shape Definition

Similar to the `geo_shape` type, the `geo_shape` Filter uses
http://www.geojson.org[GeoJSON] to represent shapes.

Given a document that looks like this:

[source,js]
--------------------------------------------------
{
    "name": "<NAME>, Berlin, Germany",
    "location": {
        "type": "Point",
        "coordinates": [13.400544, 52.530286]
    }
}
--------------------------------------------------

The following query will find the point using the Elasticsearch's
`envelope` GeoJSON extension:

[source,js]
--------------------------------------------------
{
    "query":{
        "filtered": {
            "query": {
                "match_all": {}
            },
            "filter": {
                "geo_shape": {
                    "location": {
                        "shape": {
                            "type": "envelope",
                            "coordinates" : [[13.0, 53.0], [14.0, 52.0]]
                        }
                    }
                }
            }
        }
    }
}
--------------------------------------------------

[float]
===== Pre-Indexed Shape

The Filter also supports using a shape which has already been indexed in
another index and/or index type. This is particularly useful for when
you have a pre-defined list of shapes which are useful to your
application and you want to reference this using a logical name (for
example 'New Zealand') rather than having to provide their coordinates
each time. In this situation it is only necessary to provide:

* `id` - The ID of the document that containing the pre-indexed shape.
* `index` - Name of the index where the pre-indexed shape is. Defaults
to 'shapes'.
* `type` - Index type where the pre-indexed shape is.
* `shape_field_name` - Name of the field in the document containing the
pre-indexed shape. Defaults to 'shape'.

The following is an example of using the Filter with a pre-indexed
shape:

[source,js]
--------------------------------------------------
{
    "filtered": {
        "query": {
            "match_all": {}
        },
        "filter": {
            "geo_shape": {
                "location": {
                    "indexed_shape": {
                        "id": "DEU",
                        "type": "countries",
                        "index": "shapes",
                        "shape_field_name": "location"
                    }
                }
            }
        }
    }
}
--------------------------------------------------

[float]
==== Caching

The result of the Filter is not cached by default. Setting `_cache` to
`true` will mean the results of the Filter will be cached. Since shapes
can contain 10s-100s of coordinates and any one differing means a new
shape, it may make sense to only using caching when you are sure that
the shapes will remain reasonably static.
<commit_msg>[DOCS] Changed `shape_field_name` to `path` in geo_shape filter documentation.<commit_after>[[query-dsl-geo-shape-filter]]
=== GeoShape Filter

Filter documents indexed using the `geo_shape` type.

Requires the <<mapping-geo-shape-type,geo_shape
Mapping>>.

You may also use the
<<query-dsl-geo-shape-query,geo_shape Query>>.

The `geo_shape` Filter uses the same grid square representation as the
geo_shape mapping to find documents that have a shape that intersects
with the query shape. It will also use the same PrefixTree configuration
as defined for the field mapping.

[float]
==== Filter Format

The Filter supports two ways of defining the Filter shape, either by
providing a whole shape defintion, or by referencing the name of a shape
pre-indexed in another index. Both formats are defined below with
examples.

[float]
===== Provided Shape Definition

Similar to the `geo_shape` type, the `geo_shape` Filter uses
http://www.geojson.org[GeoJSON] to represent shapes.

Given a document that looks like this:

[source,js]
--------------------------------------------------
{
    "name": "<NAME>, Berlin, Germany",
    "location": {
        "type": "Point",
        "coordinates": [13.400544, 52.530286]
    }
}
--------------------------------------------------

The following query will find the point using the Elasticsearch's
`envelope` GeoJSON extension:

[source,js]
--------------------------------------------------
{
    "query":{
        "filtered": {
            "query": {
                "match_all": {}
            },
            "filter": {
                "geo_shape": {
                    "location": {
                        "shape": {
                            "type": "envelope",
                            "coordinates" : [[13.0, 53.0], [14.0, 52.0]]
                        }
                    }
                }
            }
        }
    }
}
--------------------------------------------------

[float]
===== Pre-Indexed Shape

The Filter also supports using a shape which has already been indexed in
another index and/or index type. This is particularly useful for when
you have a pre-defined list of shapes which are useful to your
application and you want to reference this using a logical name (for
example 'New Zealand') rather than having to provide their coordinates
each time. In this situation it is only necessary to provide:

* `id` - The ID of the document that containing the pre-indexed shape.
* `index` - Name of the index where the pre-indexed shape is. Defaults
to 'shapes'.
* `type` - Index type where the pre-indexed shape is.
* `path` - The field specified as path containing the pre-indexed shape.
Defaults to 'shape'.

The following is an example of using the Filter with a pre-indexed
shape:

[source,js]
--------------------------------------------------
{
    "filtered": {
        "query": {
            "match_all": {}
        },
        "filter": {
            "geo_shape": {
                "location": {
                    "indexed_shape": {
                        "id": "DEU",
                        "type": "countries",
                        "index": "shapes",
                        "path": "location"
                    }
                }
            }
        }
    }
}
--------------------------------------------------

[float]
==== Caching

The result of the Filter is not cached by default. Setting `_cache` to
`true` will mean the results of the Filter will be cached. Since shapes
can contain 10s-100s of coordinates and any one differing means a new
shape, it may make sense to only using caching when you are sure that
the shapes will remain reasonably static.

{'fraction_non_alphanumeric': 0.16769844545329482, 'fraction_numerical': 0.009079653322327692, 'mean_word_length': 1.712686567164179, 'pattern_counts': {'":': 48, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4261805', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1796, 'n_words': 750}