Skip to main content

ElasticAdapter

Elasticsearch is a distributed search and analytics engine. @opra/elastic integrates it with the OPRA framework, providing service classes that map OPRA operations to Elasticsearch API calls and handle filter translation, codec decoding, lifecycle hooks, and projection.

ElasticAdapter is a namespace that provides utility types and functions for this integration.

import { ElasticAdapter } from '@opra/elastic';

Functions

prepareFilter

ElasticAdapter.prepareFilter(filters: FilterInput | FilterInput[]): estypes.QueryDslQueryContainer | undefined

Converts an OPRA FilterInput (or array of inputs) into an Elasticsearch query DSL container.


preparePatch

ElasticAdapter.preparePatch(doc: any): estypes.Script

Converts a patch object into an Elasticsearch Script for use in update-by-query operations.


prepareProjection

ElasticAdapter.prepareProjection(
dataType: ComplexType,
projection?: string | string[],
scope?: string,
): { includes?: string[]; excludes?: string[] } | undefined

Converts an OPRA projection into Elasticsearch _source includes/excludes.


prepareSort

ElasticAdapter.prepareSort(sort?: string[]): any[] | undefined

Converts an OPRA sort array (e.g. ['name', '-createdAt']) into an Elasticsearch sort descriptor.


parseRequest

ElasticAdapter.parseRequest(context: ExecutionContext): Promise<ElasticAdapter.TransformedRequest>

Parses an ExecutionContext and transforms it into an Elasticsearch-compatible request object. Supports Entity.Create, Entity.Get, Entity.FindMany, Entity.Update, Entity.UpdateMany, Entity.Delete, and Entity.DeleteMany operations.

Throws: TypeError if the context transport is not 'http', or Error if the operation is not supported.


Interfaces

ElasticAdapter.TransformedRequest

PropertyTypeDescription
method'create' | 'delete' | 'deleteMany' | 'get' | 'replace' | 'findMany' | 'update' | 'updateMany'The resolved operation method
keyanyThe document identifier, if applicable
dataanyThe input payload, if applicable
optionsanyThe operation options

Types

ElasticAdapter.FilterInput

type FilterInput =
| OpraFilter.Expression
| estypes.QueryDslQueryContainer
| string
| undefined;

Accepted input forms for a filter expression. Can be:

  • A raw Elasticsearch query DSL object ({ term: { status: 'active' } })
  • An OPRA filter expression object
  • An OPRA filter string ("status='active'")
  • undefined (no filter)