Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algolia browse function returning max 1000 records using Javascript

I am using algolia javascript api for retrieving all records in my index using browse function, but still it is returning 1000 records. Here is my code:

function load_location_list(){
var client = algoliasearch('ID', 'KEY');
var index_name = "locations_new";
var attribute_list = "*";
var index = client.initIndex(index_name);
index.browse({
    "attributesToRetrieve": attribute_list,
}).then(function search_Success(response) {
        console.log(response);
});

}

like image 655
Muzammil Naseer Avatar asked May 27 '16 06:05

Muzammil Naseer


People also ask

Why does Algolia return 0 results when I request a page?

If you send a request for a page that doesn’t exist, or is out-of-range, that is, when page >= nbPages, Algolia doesn’t return an error. Instead, it returns 0 results. Leveraging page and hitsPerPage is best practice for adding pagination functionality.

What is the maximum number of hits in Algolia?

Pagination Limitations 1000 hit limit By default, Algolia limits the maximum number of hits that can be retrieved via a query to 1000. This restriction is in place to not only guarantee optimal performance, but also to ensure your data cannot be easily extracted.

How do I retrieve more than 1000 hits in a search query?

The search query only allows for the retrieval of up to 1000 hits . If you need to retrieve more than 1000 hits (e.g. for SEO), you can either leverage the Browse index method or increase the paginationLimitedTo parameter. # Found an issue?

What additional fields does Algolia add to its query results?

However, Algolia does enrich them with a few additional fields, such as _highlightResult, _snippetResult, _rankingInfo, and _distinctSeqID. hits: [ { field1 : "", field2 : "", [...], _highlightResult: { [...] }, _snippetResult: { [...] }, _rankingInfo: { [...] }, _distinctSeqID : }, [...] ] The number of hits matched by the query.


1 Answers

Actually, browse doesn't return more than 1000 elements at the first call. However, the response contains a cursor that you can use to access the next elements with the browseFrom function.

However, the previous method is kind of manual. You probably want to use the browseAll function instead which lets you access all the elements sequentially.

You can find more informations about all the browse* functions in the README of the JS client (also available in the Algolia documentation).

like image 103
aseure Avatar answered Sep 23 '22 23:09

aseure