Skip to Content
Engineering11 Documentation 🔥

REST Algolia API

CQRS commands for Algolia search index synchronization.

What It Does

The REST Algolia API provides NestJS CQRS commands and handlers for integrating Algolia search functionality. It enables event-driven synchronization of records between application datastores and Algolia search indices through reusable commands.

Key Capabilities

  • CQRS Commands: Upsert, set, and delete operations as commands
  • Event-Driven Sync: Asynchronous index synchronization
  • Multi-Index Support: Runtime-specified index names
  • Flexible ID Handling: Support for record.id and custom IDs
  • Error Handling: Graceful handling of records without IDs
  • NestJS Integration: Seamless module and DI integration

Main Components

AlgoliaModule

NestJS module that registers all command handlers:

@Module({ imports: [CqrsModule], providers: [ UpsertAlgoliaRecordHandler, SetAlgoliaRecordHandler, DeleteAlgoliaRecordHandler ] })

Commands

UpsertAlgoliaRecordCommand

new UpsertAlgoliaRecordCommand(searchIndex, record, id?)

Creates or partially updates Algolia record.

SetAlgoliaRecordCommand

new SetAlgoliaRecordCommand(searchIndex, record, id?)

Creates or fully replaces Algolia record.

DeleteAlgoliaRecordCommand

new DeleteAlgoliaRecordCommand(searchIndex, id)

Deletes record from Algolia index.

Usage Pattern

Event sagas dispatch commands to sync search indices:

@EventSaga(CustomerCreatedEvent) syncToAlgolia = (events$) => events$.pipe( map(({payload}) => new UpsertAlgoliaRecordCommand( SEARCH_INDICES.CUSTOMER, payload.item ) ) )

Common Use Cases

  • Real-time search index updates
  • Event-driven search synchronization
  • Multi-index management
  • Decoupled search operations
  • Asynchronous index updates

What Customers Don’t Have to Build

  • CQRS command infrastructure for Algolia
  • Command handler implementations
  • Algolia integration boilerplate
  • Event-driven sync patterns
  • Error handling for missing IDs
  • Multi-index command support
Last updated on