Geosearch WithinGeoRange maxdistance metric not accurate

Description

Hello,

I’m having an issue with the WithinGeoRange operator for geospatial queries in my database.

Here is the query structure I’m using:

{
    'operator': 'WithinGeoRange',
    'valueGeoRange': {
        'geoCoordinates': {
            'latitude': coordinates["latitude"],
            'longitude': coordinates["longitude"],
        },
        'distance': {'max': int(distance)}
    },
    'path': ['coordinates']
}

Here is a sample document in my database:

{
    "properties": {
        "coordinates": {
            "latitude": 27.160555,
            "longitude": 78.054596
        },
        "productId": "66ea"
    }
}

When I query using the same latitude and longitude as the document (latitude: 27.160555, longitude: 78.054596) and set the max distance to 1000, I don’t get any results.

What I’ve Tried:

  1. Verified that the coordinates in the query match the document.
  2. Confirmed that the distance is correctly calculated in meters.
  3. Checked for typos in the path parameter.

Still, the query doesn’t return the document even though it should fall within the range.

Questions:

  1. Does the WithinGeoRange operator support this type of query, or am I missing something in the implementation?
  2. Is there a specific distance metric or projection setting I need to configure?
  3. Could this be related to a bug, or am I misinterpreting how the geospatial query works?

Any help or pointers would be greatly appreciated!

Server Setup Information

hi @mugndhn !!

Welcome to our community :hugs: !!

Can you reproduce this scenario in a python code?

Here is one that we can use as reference:

This helps us understand exactly what is the code you are using, with some fictional dataset, etc.

LEt me know if this helps!

Thanks!

hi @DudaNogueira,

While I was putting together the notebook for you, I noticed a typo in the query which was swapping lat and long. We were able to fix it and the geosearch seems to be working now.

Thank you.

1 Like

Oh!!

Glad to hear you were able to solve this.

Thanks for sharing!!

1 Like