🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
API client / Methods / Recommend
Required API Key: any key with the search ACL
Method signature
This method isn't available in the PHP API client

We released a new version of the PHP API client in public beta. Read the beta documentation for more information.

We released a new version of the JavaScript API client in public beta. Read the beta documentation for more information.

We released a new version of the Java API client in public beta. Read the beta documentation for more information.

You’re currently reading the JavaScript API client v4 documentation. Check the migration guide to learn how to upgrade from v3 to v4. You can still access the v3 documentation.

You’re currently reading the Ruby API client v2 documentation. Check the migration guide to learn how to upgrade from v1 to v2. You can still access the v1 documentation.

About this method

Retrieve trending facet values for a specific facet attribute.

This method is only available in the JavaScript API client.

Examples

Read the Algolia CLI documentation for more information.

1
2
3
4
5
6
7
8
9
10
11
12
13
client.getTrendingFacets([
  {
    indexName: 'your_index_name',
    threshold: 80,
    facetName: 'movie_genre'
  },
])
.then(({ results }) => {
  console.log(results);
})
.catch(err => {
  console.log(err);
});

Parameters

Parameter Description
requests
type: list of request object
Required

A list of request objects to execute.

requests âž” request object

Parameter Description
indexName
type: string
Required

The name of the target index.

threshold
type: number
Optional

Threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned.

maxRecommendations
type: number
Optional

The number of recommendations to retrieve. Depending on the available recommendations and the other request parameters, the actual number of hits may be lower than that. If maxRecommendations isn’t provided or set to 0, all matching recommendations are returned, and no fallback request is performed.

facetName
type: string
Required

The facet attribute to get recommendations for.

Response

This section shows the JSON response returned by the API. Each API client encapsulates this response inside objects specific to the programming language, so that the actual response might be different. You can view the response by using the getLogs method. Don’t rely on the order of attributes in the response, as JSON doesn’t guarantee the ordering of keys in objects.

JSON format

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
  "results": [
    {
      "exhaustiveNbHits": true,
      "exhaustiveTypo": true,
      "hits": [
        {
          "_score": 98,
          "facetName": "movie_genre",
          "facetValue": "adventure"
        },
        {
          "_score": 91.02,
          "facetName": "movie_genre",
          "facetValue": "action"
        },
        {
          "_score": 82,
          "facetName": "movie_genre",
          "facetValue": "thriller"
        }
      ],
      "hitsPerPage": 1000,
      "nbHits": 3,
      "nbPages": 1,
      "page": 0
    }
  ]
}
Field Description
results
list of result

List of results in the order they were submitted, one per query.

{
  "results": [
    {
      "hits": [
        {
          ...,
          _score: 32.72
        }
      ],
    },
  ]
}

results âž” result

The results object contains the same hits object as the one of the search method. The results do not contain objectID as they do not refer to a specific item. Each result also includes the following additional field:

Field Description
_score
number

The confidence score of the recommended facet value, the closer it’s to 100, the more relevant.

Did you find this page helpful?