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.
Hi,
Which version of Elasticsearch are you using? Could you share the mapping as well?
Thanks
I'm using ES 6.7
Here is my mapping.
"geometry": {
"type": "geo_shape",
"strategy": "recursive"
},
thanks for the response
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?
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"
}
}
}
}
}
}
Please correct me if I am wrong:
- you have a geo_shape field where you index your query polygons (index_with_polygon field).
- you have another geo_shape field holding you data points (geometry field).
As you only have points, you can set up the precision of your geometry field to a very low value and therefore increase the accuracy of the results.
Yes exaclty.
Do i have to update both index with points and polygons ?
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.
Unfortunately I'm using multi-points. Is there any more solution regarding this ?
I you are using multi-points then you just need to adjust the precision. Note that you need to reindex your points.
Do I have to set the precision to low value ?
And should I remove the recursive property as well ?
The default precision is 50m. This is what I would use:
"geometry": {
"type": "geo_shape",
"strategy": "recursive",
"precision" : "1m",
"distance_error_pct": 0.0
}
Thank you. Big help.
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.