Geosearch objects with no '_geoloc'


I’m facing an issue when using the geosearch feature. My comprehension is that when my indexed objects do not include the ‘_geoloc’ attribute, they are excluded of the results. My use case is the following : I have 2 types of offers (Physical and Digital) with the following structure :

Physical :
{ ‘offer’: { ‘id’: 1, ‘isDigital’: false}, ‘_geoloc’: { ‘lat’: 1, ‘lng’: 1} }

Digital :
{ ‘offer’: {‘id’: 2, ‘isDigital’:true} }

When I’m looking for any type of offers around me (aroundRadius=100000), the digital offer is excluded. But, I want it in all my results, without using (aroundRadius=‘all’). Is there a way to include objects (without ‘_geoloc’) in my results when using aroundRadius parameter?

P.S : making 2 requests and merging results doesn’t make sense to me

Thank you in advance.

Hi @anthony.tusi, welcome to the forum!

You are correct, when enabling aroundLatLngViaIP, records without _geoloc attribute are not included in the results.

However, there is a workaround to try with attributes:

  • Include _geoloc : Add a fake _geoloc attribute to your records such as either { lat: 0, lng: 0 } or something far like the North Pole { lat: 90, lng: 0 }
  • Expand the radius : Because aroundLatLngViaIP automatically computes a radius, you’ll need to override to get all the results using aroundRadius=all

The other workaround as you stated, is to make two queries and filter your lists:

  • Get all records with browse and store them in a list
  • Get the geoloc records sorted and store them in a list
  • Filter using custom code and remove from the first list the records present in the second one
  • Append the lists

Relevant Links:

I hope this helps with your use-case.