How to use the "near operator" in Atlas Search

I tried using the near operator to find company near certain coordinates however I am not receiving any documents.
The query i am using:

I created the index also. Like that:

{
“mappings”: {
“dynamic”: false,
“fields”: {
“about”: {
“analyzer”: “lucene.standard”,
“type”: “string”
},
“address”: {
“fields”: {
“location”: {
“indexShapes”: true,
“type”: “geo”
}
},
“type”: “document”
},
“keywords”: {
“analyzer”: “lucene.standard”,
“type”: “string”
},
“name”: {
“analyzer”: “lucene.standard”,
“type”: “string”
}
}
}
}

I also created this:

Also my schema:

Screen Shot 2020-07-19 at 1.49.11 PM

The $geoNear is working in the aggregation and i am getting the correct documents, however as you can see in the aggregation query, i need to do a search on other fields also.

Because $geoNear needs to be the first stage in the aggregation pipeline i cannot do a $search with fuzzy on other fields like ‘name’, because the $search also needs to be the first stage in the aggregation pipeline. SO i cannot use $geoNear and $search in the same aggregation pipeline.

This is where the near operator comes in. However even though it is the correct syntax i am not getting any documents. The above aggregation pipeline uses the near operator.

What am I missing here?

Hi @Abram_Thau ,

Looking into a similar example in our documentation I see that there is another level specifying “should” or “must” on the geo search part but is absent in your example:

Can you try to specify this level?

Additionally, can you clarify how many search indexes you have?

Where do you run this query? Compass or data explorer?

Have you tried a mongo shell to run it?

Best regards
Pavel

1 Like

Hi @Abram_Thau,

It would be helpful if you try to run similar query, with one of term and near operators and without the other. This way you’ll find out which one of those matches documents and which one does not.

Also note that the index: 'CustomIndex' must match the name of your defined index. If it doesn’t you might not get any results.

1 Like

@Abram_Thau Did the responses from my colleagues resolve this issue for you?

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