Best approach to find points within radius

Hi guys. I would like to get you insight on what is the best approach to use radius filtering - i.e. get points which are within a given range from the specified center.

In Java API there are two ways, based on the format in which points coordinates are stored.

1). Coordinate has a "geo_point" mapping:
"location": {
"lat": -0.32005,
"lon": 51.51321
}

Then query will look like:
QueryBuilder qb = QueryBuilders.geoDistanceQuery("location")
.point(0.32003, 51.51328)
.distance(1, DistanceUnit.KILOMETERS)
.optimizeBbox("memory")
.geoDistance(GeoDistance.SLOPPY_ARC);

2). Coordinate has a "geo_shape" mapping:
"location": {
"type": "point",
"coordinates": [
-0.32005,
51.51321
]
}

Query will look like this:
QueryBuilder qb = QueryBuilders.geoShapeQuery("location",
ShapeBuilder.newCircleBuilder()
.center(0.32003, 51.51328)
.radius(1, DistanceUnit.KILOMETERS),
ShapeRelation.WITHIN);

Both queries yield the same result. However, I am not sure which one is a recommended approach.

In my application one of the coordinates has to be geo_shape - because I perform other geo shape queries on it (like find points within geo_shape polygon). Now the question is, should I add another field for storing the same coordinates in geo_point format (in addition to geo_shape) - just for the sake of using geo distance query? Will it provide any performance benefits as compared to approach 2)?

Hi Alexey,

heres an older forum thread pointing out some differences and tradeoffs between the two approaches. Not sure how much of this has changed in recent versions but as a starting point this might help.

1 Like

Thanks a lot, Christoph!
This link gave me the needed answer.