The generated API clients are a work in progress, you can also find our stable clients on the Algolia documentation.

Skip to main content

Retrieving facets

To retrieve facets and their respective counts as part of the JSON response, you must specify a list of facets in the facets parameter at query time.

For example, you can retrieve your books’ facets with the search method, and the facets parameter.

When the facets parameter is empty, the engine returns no facet information.

import { searchClient } from '@algolia/client-search';

const client = searchClient('YOUR_APP_ID', 'YOUR_API_KEY');

const response = await client.search({
requests: [
{
indexName: '<YOUR_INDEX_NAME>',
query: '<YOUR_QUERY>',
facets: ['author', 'genre'],
},
],
});

// use typed response
console.log(response);

To extract all facet information, you can use a wildcard (*).

const response = await client.search({
requests: [
{ indexName: '<YOUR_INDEX_NAME>', query: '<YOUR_QUERY>', facets: ['*'] },
],
});

// use typed response
console.log(response);