REST API Browse Not Returning nbPages or nbHits

I am using the browse REST API endpoint indexes/${index}/browse and am posting a query to it that looks like this

body: JSON.stringify({query: '', filters: :"", hitsPerPage, page})

Where hitsPerPage and page are set to 12 and 0 (12 results per page for the first page in a query).

I was expecting to see nbPages and nbHits returned so I could implement pagination, but I am not seeing those returned. I even added in responseFields with the following array ['hits', 'nbHits', 'nbPages', 'page'] but did not see them returned still.

The response for the above documentation shows nbHits and nbPages being returned.

Any ide waht I am missing?


Hi @outdoorrackbuilder,

nbPages and nbHits fields are present only when the query is empty and the browse is not filtered.

If you need to iterate over your index objects using browse method, use the browse cursor

By the way, as you try to implement the pagination, I suppose you consider to implement the search using the browse method that it is not designed for that.
You have to use the Search method instead.

1 Like

Thanks. I guess I am misunderstanding something. I am trying to return records where an attribute condition is met. (attributeX == valueY).

But it looks like I can use filtering in the search api?

Hi @outdoorrackbuilder, yes you can use filtering on the search API.

1 Like