Skip to main content

ElasticEntityService

ElasticEntityService<T> is an abstract class that sits between ElasticService and ElasticCollectionService. It adds the index-level CRUD primitives, codec handling, and lifecycle hooks.

You do not extend it directly. Extend ElasticCollectionService instead.

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

Hierarchy: ServiceBaseElasticServiceElasticEntityService


Lifecycle hooks

Override these in ElasticCollectionService subclasses. The base implementations are no-ops.

HookSignature
_beforeCreate(command)(CreateCommand) => Promise<void>
_afterCreate(command, result)(CreateCommand, PartialDTO<T>) => Promise<void>
_beforeUpdate(command)(UpdateCommand<T>) => Promise<void>
_afterUpdate(command, result)(UpdateCommand<T>, PartialDTO<T> | undefined) => Promise<void>
_beforeUpdateMany(command)(UpdateCommand<T>) => Promise<void>
_afterUpdateMany(command, affected)(UpdateCommand<T>, number) => Promise<void>
_beforeDelete(command)(DeleteCommand) => Promise<void>
_afterDelete(command, affected)(DeleteCommand, number) => Promise<void>
_beforeDeleteMany(command)(DeleteCommand) => Promise<void>
_afterDeleteMany(command, affected)(DeleteCommand, number) => Promise<void>

Interfaces

ElasticEntityService.Options

Extends ElasticService.Options.

OptionTypeDescription
indexNamestring | ((_this) => string)Target Elasticsearch index name
resourceNamestring | ((_this) => string)Resource name used in error messages
scopestringComma-delimited scopes used to filter the API document
idGenerator(command, _this) => anyCustom ID generator for new documents

Command interfaces

Command objects are passed to lifecycle hooks. Each interface extends CommandInfo and narrows the crud discriminant.

CreateCommand

PropertyType
crud'create'
inputPartialDTO<T>
optionsCreateOptions

CountCommand

PropertyType
crud'read'
optionsCountOptions

DeleteCommand

PropertyType
crud'delete'
documentIdstring (optional)
optionsDeleteOptions | DeleteManyOptions

DeleteManyCommand

PropertyType
crud'delete'
optionsDeleteManyOptions

FindManyCommand

PropertyType
crud'read'
optionsFindManyOptions

SearchCommand

PropertyType
crud'read'
requestestypes.SearchRequest
optionsSearchOptions

UpdateCommand<T>

PropertyType
crud'update'
documentIdstring (optional)
inputPatchDTO<T>
optionsUpdateOneOptions | UpdateManyOptions

Operation options

CreateOptions

OptionTypeDescription
replaceIfExistsbooleanReplace the document if it already exists
requestStrictOmit<estypes.CreateRequest, 'id' | 'index' | 'document'>Raw Elasticsearch request options
transportTransportRequestOptionsTransport-level options

CountOptions

OptionTypeDescription
filterElasticAdapter.FilterInputFilter criteria
requestStrictOmit<estypes.CountRequest, 'index'>Raw Elasticsearch request options
transportTransportRequestOptionsTransport-level options

DeleteOptions

OptionTypeDescription
filterElasticAdapter.FilterInputAdditional filter criteria
requestStrictOmit<estypes.DeleteByQueryRequest, 'index'>Raw Elasticsearch request options
transportTransportRequestOptionsTransport-level options

DeleteManyOptions

Same shape as DeleteOptions.

FindOneOptions

Same as FindManyOptions without the limit property.

FindManyOptions

OptionTypeDescription
filterElasticAdapter.FilterInputFilter criteria
projectionstring | string[]Fields to include
sortstring[]Sort directives, e.g. ['name', '-createdAt']
limitnumberMaximum number of hits to return. Defaults to defaultLimit.
skipnumberNumber of hits to skip
noDecodebooleanSkip OPRA output decoding and return raw documents
requestStrictOmit<estypes.SearchRequest, 'index' | 'from' | 'size' | 'sort' | '_source'>Raw Elasticsearch request options
transportTransportRequestOptionsTransport-level options

SearchOptions

OptionTypeDescription
noDecodebooleanSkip OPRA output decoding
transportTransportRequestOptionsTransport-level options

UpdateOneOptions

OptionTypeDescription
filterElasticAdapter.FilterInputAdditional filter criteria
requestStrictOmit<estypes.UpdateByQueryRequest, 'index'>Raw Elasticsearch request options
transportTransportRequestOptionsTransport-level options

UpdateManyOptions

Same shape as UpdateOneOptions.