Cannot figure out simple document search by numeric attribute

Hi all,

I need to retrieve documents by non-searchable numeric document attribute ‘id’ - search by range,

My index is created as:

$res = $index->setSettings([
    'searchableAttributes' => ['name', 'description'],
    'attributesForFaceting' => [
        'filterOnly(id)',
    ],
    'ranking' => [
        'desc(pubdate)',
        'typo',
        'geo',
        'words',
        'filters',
        'proximity',
        'attribute',
        'exact',
        'custom'
    ]
]);

All documents in index have searchable name, description fields and non-searchable numeric field id.

I need to find documents in the index whose id is less than 100:

$res = $algoliaIndex->search('query', [
    'filters' => 'id < 100'
]);

However, that results in no hits. Browsing collection I can see that there are plenty of documents with id < 100.

What am I doing wrong?

Thanks!

Hi @tmr,

Thanks for contacting Algolia.

The first thing you can check is if the attribute id was successfully set as filterOnly. Can you please confirm:

  • In Algolia Dashboard, in Configuration > Facets > Attributes for Faceting is id set as " filter only"

  • If yes, can you try to manually add your filter by selecting: + Add Query Parameter > Custom > add the custom filter { "filters": "id<100"}

We created a small example index with id and values below and above 100. It worked in the Algolia Dashboard.

If your attribute is set properly and it works in the Dashboard, then the next step would be to confirm if you have proper syntax as sent from your PHP request.