# Geo\_shape query accuracy

**URL:** <https://discuss.elastic.co/t/geo-shape-query-accuracy/208244>\
**Category:** Elasticsearch\
**Created:** [November 18, 2019, 3:03am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244 "2019-11-18T03:03:02Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raven\_Ariola](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raven_ariola/32/49699_2.png) [@Raven\_Ariola](https://discuss.elastic.co/u/Raven_Ariola)\
**Post date:** [November 18, 2019, 3:03am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/1 "2019-11-18T03:03:02Z")

</div>

My geo\_shape query filters points based from a region polygon. I'm having results that is out of bounds of the polygon and I'm using within relation. Can someone help me to make the results accurate. Thanks.

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [November 18, 2019, 6:14am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/2 "2019-11-18T06:14:12Z")

</div>

Hi,

Which version of Elasticsearch are you using? Could you share the mapping as well?

Thanks

---

<div class="post-metadata">

**Author:** ![Raven\_Ariola](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raven_ariola/32/49699_2.png) [@Raven\_Ariola](https://discuss.elastic.co/u/Raven_Ariola)\
**Post date:** [November 18, 2019, 6:27am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/3 "2019-11-18T06:27:03Z")

</div>

I'm using ES 6.7

Here is my mapping.  
"geometry": {  
"type": "geo\_shape",  
"strategy": "recursive"  
},

thanks for the response

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [November 18, 2019, 6:46am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/4 "2019-11-18T06:46:14Z")

</div>

Are you indexing points or polygons? It is not clear in the description.

The issue here is that you are using a recursive strategy. This strategy uses prefix tree indexing under the hood that it is by definition not precise. Is there any reason why you specifically set the strategy to recursive?

---

<div class="post-metadata">

**Author:** ![Raven\_Ariola](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raven_ariola/32/49699_2.png) [@Raven\_Ariola](https://discuss.elastic.co/u/Raven_Ariola)\
**Post date:** [November 18, 2019, 7:21am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/5 "2019-11-18T07:21:15Z")

</div>

I'm indexing points here is my example code. I used strategy because of indexing circle polygons.

GET index\_with\_points/\_search  
{  
"query": {  
"bool": {  
"filter": {  
"geo\_shape": {  
"geometry": {  
"indexed\_shape": {  
"index": "index\_with\_polygon",  
"type": "\_doc",  
"id": "rdNUhm0BLPir2h2RirAS",  
"path": "wkb\_geometry"

```
        },
        "relation": "within"
      }
    }
  }
}

```

}  
}

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [November 18, 2019, 7:28am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/6 "2019-11-18T07:28:17Z")

</div>

Please correct me if I am wrong:

1. you have a geo\_shape field where you index your query polygons (index\_with\_polygon field).
2. you have another geo\_shape field holding you data points (geometry field).

As you only have points, you can set up the [precision](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-shape.html#geo-shape-mapping-options) of your geometry field to a very low value and therefore increase the accuracy of the results.

---

<div class="post-metadata">

**Author:** ![Raven\_Ariola](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raven_ariola/32/49699_2.png) [@Raven\_Ariola](https://discuss.elastic.co/u/Raven_Ariola)\
**Post date:** [November 18, 2019, 7:41am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/7 "2019-11-18T07:41:38Z")

</div>

Yes exaclty.

Do i have to update both index with points and polygons ?

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [November 18, 2019, 8:24am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/8 "2019-11-18T08:24:26Z")

</div>

Only the points. It is actually dangerous to set very low precision to an index with big shapes as it can produce very large indexes.

Are you indexing single points or there are multi-points as well?

If you are indexing only single points: I would recommend to set to true the mapping property `points_only`. In addition `within` and `intersects` in this case are equivalent but probably intersects implementation is faster so use it if you are in this case.

---

<div class="post-metadata">

**Author:** ![Raven\_Ariola](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raven_ariola/32/49699_2.png) [@Raven\_Ariola](https://discuss.elastic.co/u/Raven_Ariola)\
**Post date:** [November 18, 2019, 8:34am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/9 "2019-11-18T08:34:09Z")

</div>

Unfortunately I'm using multi-points. Is there any more solution regarding this ?

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [November 18, 2019, 8:48am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/10 "2019-11-18T08:48:10Z")

</div>

I you are using multi-points then you just need to adjust the precision. Note that you need to reindex your points.

---

<div class="post-metadata">

**Author:** ![Raven\_Ariola](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raven_ariola/32/49699_2.png) [@Raven\_Ariola](https://discuss.elastic.co/u/Raven_Ariola)\
**Post date:** [November 18, 2019, 9:20am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/11 "2019-11-18T09:20:38Z")

</div>

Do I have to set the precision to low value ?

---

<div class="post-metadata">

**Author:** ![Raven\_Ariola](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raven_ariola/32/49699_2.png) [@Raven\_Ariola](https://discuss.elastic.co/u/Raven_Ariola)\
**Post date:** [November 18, 2019, 9:29am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/12 "2019-11-18T09:29:41Z")

</div>

And should I remove the recursive property as well ?

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [November 18, 2019, 9:32am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/13 "2019-11-18T09:32:33Z")

</div>

The default precision is 50m. This is what I would use:

```auto
"geometry": {
   "type": "geo_shape",
    "strategy": "recursive",
    "precision" : "1m",
    "distance_error_pct": 0.0
}

```

---

<div class="post-metadata">

**Author:** ![Raven\_Ariola](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raven_ariola/32/49699_2.png) [@Raven\_Ariola](https://discuss.elastic.co/u/Raven_Ariola)\
**Post date:** [November 18, 2019, 9:41am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/14 "2019-11-18T09:41:01Z")

</div>

Thank you. Big help.

---

<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:** [December 16, 2019, 9:41am UTC](https://discuss.elastic.co/t/geo-shape-query-accuracy/208244/15 "2019-12-16T09:41:07Z")

</div>

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