Managing Data with Algolia

Learn how to manage dataset configuration before sending it to Algolia using API or dashboard. Additionally, interact with the sample code to practice customising and sending dataset using Aloglia's API.

Overview

In the previous lesson, we talked about how we can push data to the Algolia server using API or by manually using the dashboard.

In this lesson, we learn how to manage dataset configuration and customise search behaviour using API or dashboard based on what attributes can be searched (such as name, description, etc).

Using API

In order for Algolia to decide what data response (hits) to return to the user and the order of this response based on the query, we will need to set some configurations for Algolia to filter the index based on those configs and query.

To set the config for the dataset, we are going to use the setSettings method which creates the index settings, or updates if settings already exist.

Note: If specified settings already exist then they will be overridden.

The setSettings method takes an options object as a parameter. You can find the supported settings here.

The attributes used for these settings can be for searching, filtering, displaying, and so on.

index.setSettings({
   searchableAttributes: [
    'name',
    'category',
  ]
}).then(() => {
  // done
});

Given that Algolia is built to suggest results as you type, the order of attributes is important to decide which results to display first by order of importance, the most important being displayed first.

The above searchableAttributes indicate that the results of the user search query will be based on name and category.

In other words, we can customise how results get displayed based on searchableAttributes and other additional settings such as attributesForFaceting which are attributes used for filtering results (It will be discussed in more details in a later lesson).

index.setSettings({
   searchableAttributes: [
    'name',
    'category',
  ]
}).then(() => {
  // done
});

Here is an example response of what you get by executing the setSettings method, which includes the taskID and the date on which the indexing job has been created.

{ updatedAt: '2021-02-08T22:16:38.213Z', taskID: 92610454000 }

Get hands-on with 1200+ tech skills courses.