user2954587
user2954587

Reputation: 4861

algolia facets returns empty object in javascript API client

I'm using the Javascript API Client and would like to have facets return on my index. I believe faceting is turned on for the index because 1. I toggled the switch in the UI 2. I can use faceting in the dashboard for my index. I set up my index with the following params:

var params = {
  tagFilters: 'query',
  aroundLatLngViaIP: true,
  getRankingInfo: 1,
  facets: "*"
};

However, this returns an empty facets object. How can I receive a facet object with all possible faceting options?

JSFiddle

Upvotes: 3

Views: 450

Answers (1)

Jerska
Jerska

Reputation: 12032

You have no result for this query, hence the lack of facet.
You can maybe see it more easily on this updated JSFiddle:

index.search(params).then(function(resp) {
  count.innerText = resp.hits.length + ' results';
  facets.innerText = JSON.stringify(resp.facets, null, 2);
  response.innerText = JSON.stringify(resp, null, 2);
});

Upvotes: 4

Related Questions