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 shape | Use |
|---|---|
| An Elasticsearch index | ElasticCollectionService |
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()andupdate()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.).findManyWithCountreturns arelationfield alongsideitemsandcount(Elasticsearch's hit total relation).
Guides
- Getting Started — first service, client connection, NestJS wiring
- Querying — filter, projection, sort, pagination, raw search
- Mutations — create, update, delete
- Lifecycle Hooks — validation, audit logging, computed fields
- Interceptors — cross-cutting logic