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.

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

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

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