Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get total number of records in index for Algolia - Javascript

How can i get the total number of records in an index, with algolia?

I'd like to avoid doign an empty search with a number of items per page set to a million or something.

like image 828
Ascherer Avatar asked Nov 24 '25 16:11

Ascherer


1 Answers

Every search result from Algolia has an attribute of nbHits. To get the total number of records, do an empty query with no filters and grab that number.

If you care about the size of the results, you can also set the attributesToRetrieve to null which will return only the objectID and make the result a bit snappier.

like image 134
dcoates Avatar answered Nov 27 '25 05:11

dcoates



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!