Is it possible to get all Facets values (like RefinimentList) with vanilla javascript?

Like in your example, if I have a Facet “brands” [“Samsung”, “Apple”, “GE”, “HP”, “SONY” etc…]

Is it possible to retrieve all possible brands and their counts? Without using React. I have a very custom UI with React Native and would love to do this the vanilla way if possible.

Hi @postkulture, you can retrieve facets using the search method, with the facets search parameter to designate which facets you want to retrieve (using an asterisk * will select them all). If you use an empty query, you will get all the values for each facet. You will also get the hits.

One thing to note is that if you have a lot of records, you may run into inexhaustivity and not get all the hits, nor all the facets. You can check the exhaustiveNbHits parameter to see if you reached exhaustivity. It’s always best to get the complete list of facet values from your original data source when possible.

Hi @cindy.cullen I can’t find a way to see neither the Facets nor its counts on the result, am I missing something?

I’m using Algolia’s start example as base, and this is the code:

const searchClient = algoliasearch(
	'B1G2GM9NG0',
	'aadef574be1f9252bb48d4ea09b5cfe5'
);
const index = searchClient.initIndex('demo_ecommerce');

index.search('', {
	facets: ['*']
}).then(({ hits }) => {
	console.log(hits);
});

and the Sandbox

Hi!

I forked and modified your Code sandbox to make it work. See agitated-http-u8p9w - CodeSandbox

In a nutshell: the facets are received on the property facets of the response, and not hits.

1 Like