Hi all,
I am looking to use Atlas Search and the near operator to find records that satisfy both the search criteria and are near a given geo point. I created a 2d index for the field location, which follows the structure mentioned in the documentation.
When I try to find documents using only the near function, everything works fine. Similarly, using the search query with Atlas Search also works correctly. However, I am struggling to use both operators in the same aggregation query.
The error I encounter is:
Failed to run this query. Reason: geoWithin requires path 'location' to be indexed as 'geo'
The query I am running is:
{
$search: {
index: "default",
compound: {
must: [
{
text: { query: "text", path: "*" },
},
{
near: {
path: "location",
origin: {
type: "Point",
coordinates: [
45.464203, 9.189982,
],
},
pivot: 100000,
},
},
],
},
},
},
]`
location field:

Index field

Atlas Search index:

Query error:

The same error was also raised from NodeJs.
Any idea what I am doing wrong?
Thanks in advance.


