Skip to main content

elasticsearch-store / index-model / IndexModel

Class: abstract IndexModel<T>

An high-level, opinionated, abstract class for an elasticsearch DataType, with a CRUD-like interface

Extends

Type parameters

Type parameter
T extends IndexModelRecord

Constructors

new IndexModel()

new IndexModel<T>(client, options, modelConfig): IndexModel<T>

Parameters

ParameterType
clientClient
optionsIndexModelOptions
modelConfigIndexModelConfig<T>

Returns

IndexModel<T>

Overrides

IndexStore.constructor

Source

elasticsearch-store/src/index-model.ts:28

Properties

_defaultQueryAccess

protected _defaultQueryAccess: undefined | QueryAccess<T>

Inherited from

IndexStore._defaultQueryAccess

Source

elasticsearch-store/src/index-store.ts:35


client

readonly client: Client

Inherited from

IndexStore.client

Source

elasticsearch-store/src/index-store.ts:29


clientMetadata

readonly clientMetadata: ClientMetadata

Inherited from

IndexStore.clientMetadata

Source

elasticsearch-store/src/index-store.ts:34


config

readonly config: IndexConfig<T>

Inherited from

IndexStore.config

Source

elasticsearch-store/src/index-store.ts:30


logger

readonly logger: Logger

Source

elasticsearch-store/src/index-model.ts:23


manager

readonly manager: IndexManager

Inherited from

IndexStore.manager

Source

elasticsearch-store/src/index-store.ts:31


name

readonly name: string

Overrides

IndexStore.name

Source

elasticsearch-store/src/index-model.ts:22


readHooks

readonly readHooks: Set<ReadHook<T>>

Inherited from

IndexStore.readHooks

Source

elasticsearch-store/src/index-store.ts:39


refreshByDefault

refreshByDefault: boolean = true

Inherited from

IndexStore.refreshByDefault

Source

elasticsearch-store/src/index-store.ts:33


writeHooks

readonly writeHooks: Set<WriteHook<T>>

Inherited from

IndexStore.writeHooks

Source

elasticsearch-store/src/index-store.ts:38


xLuceneTypeConfig

readonly xLuceneTypeConfig: xLuceneTypeConfig

Inherited from

IndexStore.xLuceneTypeConfig

Source

elasticsearch-store/src/index-store.ts:36

Accessors

searchIndex

get searchIndex(): string

The index typically used for searching across all of the open indices

Returns

string

Source

elasticsearch-store/src/index-store.ts:108


writeIndex

get writeIndex(): string

The most current indexed used to write to

Returns

string

Source

elasticsearch-store/src/index-store.ts:101

Methods

_ensureUnique()

protected _ensureUnique(record, existing?): Promise<void>

Parameters

ParameterType
recordT
existing?T

Returns

Promise<void>

Source

elasticsearch-store/src/index-model.ts:239


_sanitizeRecord()

protected _sanitizeRecord(record): T

Parameters

ParameterType
recordT

Returns

T

Source

elasticsearch-store/src/index-model.ts:215


protected _search(params): Promise<SearchResponse<T>>

A small abstraction on client.search with retry support

Parameters

ParameterType
paramsPartialParam<SearchParams, any>

Returns

Promise<SearchResponse<T>>

Inherited from

IndexStore._search

Source

elasticsearch-store/src/index-store.ts:744


_toRecord()

protected _toRecord(result, critical): T

Parameters

ParameterTypeDefault value
resultSearchResult<T>undefined
criticalbooleantrue

Returns

T

Inherited from

IndexStore._toRecord

Source

elasticsearch-store/src/index-store.ts:874


_toRecords()

protected _toRecords(results, critical): T[]

Parameters

ParameterTypeDefault value
resultsSearchResult<T>[]undefined
criticalbooleanfalse

Returns

T[]

Inherited from

IndexStore._toRecords

Source

elasticsearch-store/src/index-store.ts:886


aggregate()

aggregate<A>(query, params?): Promise<A>

Run an aggregation using an Elasticsearch Query DSL

Type parameters

Type parameterValue
ASearchAggregations

Parameters

ParameterType
queryRecord<string, any>
params?PartialParam<SearchParams, any>

Returns

Promise<A>

Inherited from

IndexStore.aggregate

Source

elasticsearch-store/src/index-store.ts:728


appendToArray()

appendToArray(id, field, values): Promise<void>

Append values from an array on a record. Use with caution, this may not work in all cases.

Parameters

ParameterType
idstring
fieldkeyof T
valuesstring | string[]

Returns

Promise<void>

Inherited from

IndexStore.appendToArray

Source

elasticsearch-store/src/index-store.ts:793


bulk()

bulk(action, id)

bulk(action, id): Promise<void>

Safely add a create, index, or update requests to the bulk queue

This method will batch messages using the configured bulk max size and wait configuration.

Because using the upsert-with-script api since that can break depending on the underlying elasticsearch version and/or client library

Parameters
ParameterType
action"delete"
idstring
Returns

Promise<void>

Inherited from

IndexStore.bulk

Todo

we need to add concurrency support for sending multiple bulk requests in flight and making sure they finish before shutdown

Source

elasticsearch-store/src/index-store.ts:127

bulk(action, doc, id, retryOnConflict, onBulkQueueConflict)

bulk(action, doc, id?, retryOnConflict?, onBulkQueueConflict?): Promise<void>

Parameters
ParameterType
action"index" | "create"
docPartial<T>
id?string
retryOnConflict?number
onBulkQueueConflict?OnBulkConflictFn<T>
Returns

Promise<void>

Inherited from

IndexStore.bulk

Source

elasticsearch-store/src/index-store.ts:128

bulk(action, doc, id, retryOnConflict, onBulkQueueConflict)

bulk(action, doc, id?, retryOnConflict?, onBulkQueueConflict?): Promise<void>

Parameters
ParameterType
action"update"
docPartial<T>
id?string
retryOnConflict?number
onBulkQueueConflict?OnBulkConflictFn<T>
Returns

Promise<void>

Inherited from

IndexStore.bulk

Source

elasticsearch-store/src/index-store.ts:129

bulk(action, script, id, retryOnConflict, onBulkQueueConflict)

bulk(action, script, id?, retryOnConflict?, onBulkQueueConflict?): Promise<void>

Parameters
ParameterType
action"upsert-with-script"
scriptUpsertWithScript<T>
id?string
retryOnConflict?number
onBulkQueueConflict?OnBulkConflictFn<T>
Returns

Promise<void>

Inherited from

IndexStore.bulk

Source

elasticsearch-store/src/index-store.ts:130


bulkCreateRecords()

bulkCreateRecords(records, allowOverrides?): Promise<void>

Create a bulk records and put it them into bulk request queue

Parameters

ParameterType
recordsCreateRecordInput<T>[]
allowOverrides?boolean

Returns

Promise<void>

Source

elasticsearch-store/src/index-model.ts:160


count()

count(query?, options?, queryAccess?): Promise<number>

Count records by a given Lucene Query

Parameters

ParameterType
query?string
options?RestrictOptions
queryAccess?QueryAccess<T>

Returns

Promise<number>

Inherited from

IndexStore.count

Source

elasticsearch-store/src/index-store.ts:218


countBy()

countBy(fields, joinBy?, options?, queryAccess?): Promise<number>

Parameters

ParameterType
fieldsAnyInput<T>
joinBy?JoinBy
options?RestrictOptions
queryAccess?QueryAccess<T>

Returns

Promise<number>

Inherited from

IndexStore.countBy

Source

elasticsearch-store/src/index-store.ts:527


countRecords()

countRecords(fields, clientId?, joinBy?, options?, queryAccess?): Promise<number>

Parameters

ParameterType
fieldsAnyInput<T>
clientId?number
joinBy?JoinBy
options?RestrictOptions
queryAccess?QueryAccess<T>

Returns

Promise<number>

Source

elasticsearch-store/src/index-model.ts:188


countRequest()

countRequest(params): Promise<number>

Count records by a given Elasticsearch Query DSL

Parameters

ParameterType
paramsCountParams

Returns

Promise<number>

Inherited from

IndexStore.countRequest

Source

elasticsearch-store/src/index-store.ts:232


create()

create(doc, params?): Promise<T>

Create a document but will throw if doc already exists

Parameters

ParameterType
docPartial<T>
params?PartialParam<CreateParams<T>, "body">

Returns

Promise<T>

the created record

Inherited from

IndexStore.create

Source

elasticsearch-store/src/index-store.ts:262


createById()

createById(id, doc, params?): Promise<T>

Create a document with an id

Parameters

ParameterType
idstring
docPartial<T>
params?PartialParam<CreateParams<T>, "body" | "id">

Returns

Promise<T>

the created record

Inherited from

IndexStore.createById

Source

elasticsearch-store/src/index-store.ts:250


createJoinQuery()

createJoinQuery(fields, joinBy, variables): xLuceneQueryResult

Parameters

ParameterTypeDefault value
fieldsAnyInput<T>undefined
joinByJoinBy'AND'
variablesobject{}

Returns

xLuceneQueryResult

Inherited from

IndexStore.createJoinQuery

Source

elasticsearch-store/src/index-store.ts:778


createRecord()

createRecord(record, allowOverrides?): Promise<T>

Parameters

ParameterType
recordCreateRecordInput<T>
allowOverrides?boolean

Returns

Promise<T>

Source

elasticsearch-store/src/index-model.ts:114


deleteById()

deleteById(id, params?): Promise<void>

Deletes a document for a given id

Parameters

ParameterType
idstring
params?PartialParam<DeleteParams, any>

Returns

Promise<void>

Inherited from

IndexStore.deleteById

Source

elasticsearch-store/src/index-store.ts:408


deleteRecord()

deleteRecord(id, clientId?): Promise<boolean>

Soft deletes a record by ID

Parameters

ParameterType
idstring
clientId?number

Returns

Promise<boolean>

Source

elasticsearch-store/src/index-model.ts:173


exists()

exists(id, options?, queryAccess?): Promise<boolean>

Parameters

ParameterType
idstring | string[]
options?RestrictOptions
queryAccess?QueryAccess<T>

Returns

Promise<boolean>

Inherited from

IndexStore.exists

Source

elasticsearch-store/src/index-store.ts:538


fetchRecord()

fetchRecord(anyId, options?, queryAccess?): Promise<T>

Fetch a record by any unique ID

Parameters

ParameterType
anyIdstring
options?FindOneOptions<T>
queryAccess?QueryAccess<T>

Returns

Promise<T>

Source

elasticsearch-store/src/index-model.ts:99


findAll()

findAll(ids, options?, queryAccess?): Promise<T[]>

Parameters

ParameterType
idsundefined | string | string[]
options?FindOneOptions<T>
queryAccess?QueryAccess<T>

Returns

Promise<T[]>

Inherited from

IndexStore.findAll

Source

elasticsearch-store/src/index-store.ts:637


findAllBy()

findAllBy(fields, joinBy?, options?, queryAccess?): Promise<T[]>

Parameters

ParameterType
fieldsAnyInput<T>
joinBy?JoinBy
options?FindOptions<T>
queryAccess?QueryAccess<T>

Returns

Promise<T[]>

Inherited from

IndexStore.findAllBy

Source

elasticsearch-store/src/index-store.ts:587


findAndApply()

findAndApply(updates, options?, queryAccess?): Promise<Partial<T>>

Parameters

ParameterType
updatesundefined | Partial<T>
options?FindOneOptions<T>
queryAccess?QueryAccess<T>

Returns

Promise<Partial<T>>

Inherited from

IndexStore.findAndApply

Source

elasticsearch-store/src/index-store.ts:619


findBy()

findBy(fields, joinBy?, options?, queryAccess?): Promise<T>

Parameters

ParameterType
fieldsAnyInput<T>
joinBy?JoinBy
options?FindOneOptions<T>
queryAccess?QueryAccess<T>

Returns

Promise<T>

Inherited from

IndexStore.findBy

Source

elasticsearch-store/src/index-store.ts:553


findById()

findById(id, options?, queryAccess?): Promise<T>

Parameters

ParameterType
idstring
options?FindOneOptions<T>
queryAccess?QueryAccess<T>

Returns

Promise<T>

Inherited from

IndexStore.findById

Source

elasticsearch-store/src/index-store.ts:605


flush()

flush(flushAll): Promise<void>

Parameters

ParameterTypeDefault value
flushAllbooleanfalse

Returns

Promise<void>

Inherited from

IndexStore.flush

Source

elasticsearch-store/src/index-store.ts:286


get()

get(id, params?): Promise<T>

Get a single document

Parameters

ParameterType
idstring
params?PartialParam<GetParams, any>

Returns

Promise<T>

Inherited from

IndexStore.get

Source

elasticsearch-store/src/index-store.ts:303


getDefaultParams()

getDefaultParams<P>(index, ...params): P

Type parameters

Type parameterValue
P extends Record<string, any>object

Parameters

ParameterType
indexstring
...params(undefined | Partial<P> & Record<string, any>)[]

Returns

P

Inherited from

IndexStore.getDefaultParams

Source

elasticsearch-store/src/index-store.ts:510


index()

index(doc, params?): Promise<T>

Index a document

Parameters

ParameterType
docT | Partial<T>
params?PartialParam<IndexParams<T>, "body">

Returns

Promise<T>

Inherited from

IndexStore.index

Source

elasticsearch-store/src/index-store.ts:335


indexById()

indexById(id, doc, params?): Promise<T>

A convenience method for indexing a document with an ID

Parameters

ParameterType
idstring
docT | Partial<T>
params?PartialParam<IndexParams<T>, "type" | "index" | "id">

Returns

Promise<T>

Inherited from

IndexStore.indexById

Source

elasticsearch-store/src/index-store.ts:359


initialize()

initialize(): Promise<void>

Connect and validate the index configuration.

Returns

Promise<void>

Inherited from

IndexStore.initialize

Source

elasticsearch-store/src/index-store.ts:320


mget()

mget(body, params?): Promise<T[]>

Get multiple documents at the same time

Parameters

ParameterType
bodyMGetBody
params?PartialParam<MGetParams, any>

Returns

Promise<T[]>

Inherited from

IndexStore.mget

Source

elasticsearch-store/src/index-store.ts:370


migrateIndex()

migrateIndex(options): Promise<any>

Parameters

ParameterType
optionsMigrateIndexStoreOptions

Returns

Promise<any>

Inherited from

IndexStore.migrateIndex

See

IndexManager#migrateIndex

Source

elasticsearch-store/src/index-store.ts:387


recordExists()

recordExists(id, clientId?): Promise<boolean>

Parameters

ParameterType
idstring | string[]
clientId?number

Returns

Promise<boolean>

Source

elasticsearch-store/src/index-model.ts:204


refresh()

refresh(params?): Promise<void>

Refreshes the current index

Parameters

ParameterType
params?PartialParam<IndicesRefreshParams, any>

Returns

Promise<void>

Inherited from

IndexStore.refresh

Source

elasticsearch-store/src/index-store.ts:394


removeFromArray()

removeFromArray(id, field, values): Promise<void>

Remove values from an array on a record. Use with caution, this may not work in all cases.

Parameters

ParameterType
idstring
fieldkeyof T
valuesstring | string[]

Returns

Promise<void>

Inherited from

IndexStore.removeFromArray

Source

elasticsearch-store/src/index-store.ts:823


search(q?, options?, queryAccess?, critical?): Promise<SearchResult<T>>

Search with a given Lucene Query

Parameters

ParameterType
q?string
options?FindOptions<T>
queryAccess?QueryAccess<T>
critical?boolean

Returns

Promise<SearchResult<T>>

Inherited from

IndexStore.search

Source

elasticsearch-store/src/index-store.ts:673


searchRequest()

searchRequest(params, critical?): Promise<SearchResult<T>>

Search using the underlying Elasticsearch Query DSL

Parameters

ParameterType
paramsPartialParam<SearchParams, any>
critical?boolean

Returns

Promise<SearchResult<T>>

Inherited from

IndexStore.searchRequest

Source

elasticsearch-store/src/index-store.ts:708


shutdown()

shutdown(): Promise<void>

Shutdown, flush any pending requests and cleanup

Returns

Promise<void>

Inherited from

IndexStore.shutdown

Source

elasticsearch-store/src/index-store.ts:429


update()

update(id, body, params?): Promise<void>

Update a document with a given id

Parameters

ParameterType
idstring
bodyUpdateBody<T>
params?PartialParam<UpdateParams<unknown, unknown>, "body" | "id">

Returns

Promise<void>

Inherited from

IndexStore.update

Source

elasticsearch-store/src/index-store.ts:442


updatePartial()

updatePartial(id, applyChanges, retriesOnConflict): Promise<T>

Safely apply updates to a document by applying the latest changes

Parameters

ParameterTypeDefault value
idstringundefined
applyChangesApplyPartialUpdates<T>undefined
retriesOnConflictnumber3

Returns

Promise<T>

Inherited from

IndexStore.updatePartial

Source

elasticsearch-store/src/index-store.ts:475


updateRecord()

updateRecord(id, record): Promise<T>

Parameters

ParameterType
idstring
recordUpdateRecordInput<T>

Returns

Promise<T>

Source

elasticsearch-store/src/index-model.ts:141