Filter by Geolocation only when applies

Hello, I have some mixed data on an index, which only part of the data has geolocation data. I wish to filter the data which has the geolocation data and leave the rest of the data untouched.

Is it possible to do at the moment?

Hi @minoru,

A Geo Search (that is a request leveraging the _geoloc attribute) will always disregard any record that doesn’t have any geolocation information (i.e. a _geoloc attribute). You will not get both geolocated and non-geolocated records returned in the same API response.

If you are trying to do a search unrelated to Geo Search and you only want records with the _geoloc attribute, you can also enrich your records with an additional attribute.

For example, at indexing time you can add a hasGeo:true/false boolean attribute:

{
    "name": "my geo record",
    "hasGeo": true,
    "_geoloc": {
        "lat": 40.639751,
        "lng": -73.778925
    }
}
{
    "name": "my no geo record",
    "hasGeo": false
}

Then you can apply a boolean filter to retrieve the records with geo data:

index.search('your query', { filters: 'hasGeo=1'} 

Hey, @ajay.david. Thanks for the response. I worked around making 2 separate calls and merging them before returning the result. It would be a nice feature if there was any configuration about only filtering whenever the data is available or not.

Indeed, @minoru, the feature you described below is one people contact us about:

At the moment, Algolia cannot retrieve based on null/non-null values and always has to be able to reference a value (string, numeric, boolean) which is why we suggest either the boolean attribute or adding a _tags (e.g., hasGeo) <= would do the same thing as boolean basically. Thanks for the suggestion!