Skip to content

IndexSync

Juraj Bielik edited this page Oct 16, 2019 · 6 revisions

Kentico Kontent Docs - Index Sync

Overview

Index Sync is a microservice responsible for keeping the Algolia index up-to-date. The service reacts upon a blob created in the Azure Blob Storage by either Tutorial Search service or API Reference Search service and updates the index adequately.

diagrams-Index-Sync

Specification

Triggers

The Index sync service contains two Azure functions: kcd-clear-index with an HTTP trigger and kcd-index-sync with an EventGrid event trigger.

HTTP - clear index

The HTTP trigger serves for clearing the Algolia index. It was chosen to react to HTTP requests in order to provide a way for other services to clear the index and wait for the operation to finish.

EventGrid - index sync

The Index sync Azure function is triggered by events in EventGrid which are automatically created when a blob is created in the Azure Blob Storage.

How it works

In order to understand how this service works, read the introduction to Algolia beforehand.

The clear index function extracts two query parameters: isTest and section. The isTest parameters is included in the query with value enabled when the function is supposed to run with test configuration, which is used for the integration tests. The second parameter section indicates which part of the index is supposed to be cleared: tutorials or API.

The index sync function receives an event which includes information about the blob stored by Tutorial search or API reference search in the Azure Blob Storage. Whether to choose live/test configuration is decided from the container name in which the blob has been stored. The blob containing the records to index is retrieved from an URL that is a part of the EventGrid event. The records may contain special marks that are used on the Kentico Kontent Docs website (e.g. {@icon-light-bulb@}), but they are unwanted in the search index so they are not shown in the search results. That's why all the records are sanitized - stripped of any unwanted marks that may occur in the content or heading.

There are 3 cases that may occur:

  1. deleted root item - the blob contains only the codename of the root item and has 0 records - all records related to the root item will be deleted from Algolia

  2. initialize - the blob contains flag initialiaze set to true - all records will be indexed to Algolia

  3. updated item - the Index sync service provides an optimization to reduce number of indexing operations when updating records - first, records related to the root item are retrieved and compared to the records from the blob - only the records that are different will be updated in the Algolia index