ESDocument
A small implementation of an Elasticsearch document base class.
API
-
static get(id: string): Promise<Document | null>
-
static mget(ids: string[]): Promise<Array<Document | null>>
-
static search(body: object): Promise<{ total: number, data: Document[] }>
: works great withbodybuilder
. -
static create(): Document
: creating a document. Never call the constructor directly! You can implementstatic afterCreate(obj: Document)
instead.
The return value of these static methods are typed to be the instance type of
the class the method is called on. In test.ts
, the TypeScript compiler
correctly infers the type to be User
, so you can benefit from editor tooling
in VS Code and other editors.
The instances of Document
have the following base functionality:
-
isNew(): boolean
-
getDocId(): string
-
store(): Promise<void>