Skip to main content

Elasticsearch

@opra/elastic integrates Elasticsearch with the OPRA framework. It provides a service base class that handles filter translation, codec decoding, projection, pagination, lifecycle hooks, and the for(context) per-request wiring — leaving your code focused on business logic.

npm install @opra/elastic @elastic/elasticsearch

Service

There is a single concrete service class for Elasticsearch:

Your data shapeUse
An Elasticsearch indexElasticCollectionService

Service hierarchy

ElasticService shared base: client, interceptor, onError
└── ElasticEntityService CRUD primitives + lifecycle hooks
└── ElasticCollectionService full CRUD on an index

Key differences from MongoDB and SQL

  • create() and update() do not return the document. They return Elasticsearch response objects (CreateResponse, UpdateByQueryResponse). Fetch the document separately if needed.
  • No transactions. Elasticsearch does not support ACID transactions across documents.
  • No singleton service. There is only ElasticCollectionService.
  • searchRaw() — escape hatch for raw Elasticsearch queries (aggregations, highlighting, etc.).
  • findManyWithCount returns a relation field alongside items and count (Elasticsearch's hit total relation).

Guides