# Geo-polygon query inside ingest pipeline

**URL:** <https://discuss.elastic.co/t/geo-polygon-query-inside-ingest-pipeline/274886>\
**Category:** Elasticsearch\
**Created:** [June 3, 2021, 2:02pm UTC](https://discuss.elastic.co/t/geo-polygon-query-inside-ingest-pipeline/274886 "2021-06-03T14:02:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy\_Levy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roy_levy/32/61613_2.png) [@Roy\_Levy](https://discuss.elastic.co/u/Roy_Levy)\
**Post date:** [June 3, 2021, 2:02pm UTC](https://discuss.elastic.co/t/geo-polygon-query-inside-ingest-pipeline/274886/1 "2021-06-03T14:02:37Z")

</div>

Hey,

I want to use the Geo-polygon query ([Geo-polygon query | Elasticsearch Guide [7.13] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html)) inside an ingest pipeline and I've been thinking how to do it - as there is no query processor and the example for the geo polygon is with this type of query.

The reason for me trying to use this tool is to enrich documents which's country location is null, by checking their `lat` and `lon` fields and determining which country the doc is from.

Is there anyway this could be done in a pipeline?

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [June 6, 2021, 1:46am UTC](https://discuss.elastic.co/t/geo-polygon-query-inside-ingest-pipeline/274886/2 "2021-06-06T01:46:26Z")

</div>

I am thinking this is exactly what you are looking for?

> **[Example: Enrich your data based on geolocation | Elasticsearch Guide \[7.13\] |...](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-match-enrich-policy-type.html)**

---

<div class="post-metadata">

**Author:** ![Roy\_Levy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roy_levy/32/61613_2.png) [@Roy\_Levy](https://discuss.elastic.co/u/Roy_Levy)\
**Post date:** [June 7, 2021, 3:17pm UTC](https://discuss.elastic.co/t/geo-polygon-query-inside-ingest-pipeline/274886/3 "2021-06-07T15:17:12Z")

</div>

It seems like the way to go for me, but when I'm trying this example I have too many coordinates in my Polygon shape that it does not fit in the queries in the DevTools. Is there any way to get the max query size up in DevTools?

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [June 7, 2021, 3:22pm UTC](https://discuss.elastic.co/t/geo-polygon-query-inside-ingest-pipeline/274886/4 "2021-06-07T15:22:16Z")

</div>

Perhaps just import a GEO JSON file from the Maps App.  
That might be easier.

---

<div class="post-metadata">

**Author:** ![Roy\_Levy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roy_levy/32/61613_2.png) [@Roy\_Levy](https://discuss.elastic.co/u/Roy_Levy)\
**Post date:** [June 7, 2021, 4:03pm UTC](https://discuss.elastic.co/t/geo-polygon-query-inside-ingest-pipeline/274886/5 "2021-06-07T16:03:40Z")

</div>

Ohhh that's a cool feature I didn't know of!  
Thanks! 😄

---

<div class="post-metadata">

**Author:** ![Roy\_Levy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roy_levy/32/61613_2.png) [@Roy\_Levy](https://discuss.elastic.co/u/Roy_Levy)\
**Post date:** [June 9, 2021, 2:22pm UTC](https://discuss.elastic.co/t/geo-polygon-query-inside-ingest-pipeline/274886/6 "2021-06-09T14:22:29Z")

</div>

Hey, I'm really close to having this all figured out - I'm creating a pipeline with an enrichment policy like you suggested and it works, but the coordinates used in the policy are very big.

When I'm getting a document through the pipeline the new enriched document has the fields I've specified in `enrich_fields` , but it also has the coordinates used to make the comparison. Is there any way to not add the `coordinates` field to every pipelined document?

This is the policy that I'm using:

```auto
PUT /_enrich/policy/county_and_state_policy
{
  "geo_match": {
    "indices": ["county_index1", "county_index2"],
    "match_field": "coordinates",
    "enrich_fields": ["county_name", "state_name"]
  }
}

```

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [June 9, 2021, 3:11pm UTC](https://discuss.elastic.co/t/geo-polygon-query-inside-ingest-pipeline/274886/7 "2021-06-09T15:11:42Z")

</div>

Are you doing point in polygon match or polygon intersects match?

What does the actual enrich processor look like / take as arguments?

I think the match field is always returned.

> The `target_field` used to store appended enrich data for incoming documents. This field contains the `match_field` and `enrich_fields` specified in your enrich policy.

You can always do a drop processor afterwards to get rid of that field.

---

<div class="post-metadata">

**Author:** ![Roy\_Levy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roy_levy/32/61613_2.png) [@Roy\_Levy](https://discuss.elastic.co/u/Roy_Levy)\
**Post date:** [June 9, 2021, 3:20pm UTC](https://discuss.elastic.co/t/geo-polygon-query-inside-ingest-pipeline/274886/8 "2021-06-09T15:20:03Z")

</div>

I'm doing polygon intersects match with coordinates and lat, lon as input for the intersection.  
Yeah seems like there is no way to exclude it, so I think I'll go with your option to get rid of it afterwards.

Thank you very much for the help! 😄

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [June 9, 2021, 9:17pm UTC](https://discuss.elastic.co/t/geo-polygon-query-inside-ingest-pipeline/274886/9 "2021-06-09T21:17:50Z")

</div>

If you want to open an issue in GitHub please do let me know if you do and I'll tag onto it

> **[elastic/elasticsearch](https://github.com/elastic/elasticsearch/issues)**
>
> Free and Open, Distributed, RESTful Search Engine. Contribute to elastic/elasticsearch development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Roy\_Levy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roy_levy/32/61613_2.png) [@Roy\_Levy](https://discuss.elastic.co/u/Roy_Levy)\
**Post date:** [June 10, 2021, 12:00pm UTC](https://discuss.elastic.co/t/geo-polygon-query-inside-ingest-pipeline/274886/10 "2021-06-10T12:00:45Z")

</div>

Hey Stephen,

I've created the feature issue in GitHub: [Excluding match\_field from geolocation enrich policy · Issue #74001 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/74001)

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 8, 2021, 12:01pm UTC](https://discuss.elastic.co/t/geo-polygon-query-inside-ingest-pipeline/274886/11 "2021-07-08T12:01:36Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
