Skip to main content

elasticsearch-store / index-model / IndexModel

Abstract Class: IndexModel<T>

Defined in: index-model.ts:22

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

Extends​

Type Parameters​

Type Parameter
T extends IndexModelRecord

Constructors​

Constructor​

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

Defined in: index-model.ts:29

Parameters​

ParameterType
clientClient
optionsIndexModelOptions
modelConfigIndexModelConfig<T>

Returns​

IndexModel<T>

Overrides​

IndexStore.constructor

Properties​

PropertyModifierTypeDefault valueOverridesInherited fromDefined in
_defaultQueryAccessprotectedQueryAccess<T> | undefinedundefined-IndexStore._defaultQueryAccessindex-store.ts:34
clientreadonlyClientundefined-IndexStore.clientindex-store.ts:28
clientMetadatareadonlyClientMetadataundefined-IndexStore.clientMetadataindex-store.ts:33
configreadonlyIndexConfig<T>undefined-IndexStore.configindex-store.ts:29
loggerreadonlyLoggerundefined--index-model.ts:24
managerreadonlyIndexManagerundefined-IndexStore.managerindex-store.ts:30
namereadonlystringundefinedIndexStore.name-index-model.ts:23
readHooksreadonlySet<ReadHook<T>>undefined-IndexStore.readHooksindex-store.ts:38
refreshByDefaultpublicbooleantrue-IndexStore.refreshByDefaultindex-store.ts:32
writeHooksreadonlySet<WriteHook<T>>undefined-IndexStore.writeHooksindex-store.ts:37
xLuceneTypeConfigreadonlyxLuceneTypeConfigundefined-IndexStore.xLuceneTypeConfigindex-store.ts:35

Accessors​

searchIndex​

Get Signature​

get searchIndex(): string

Defined in: index-store.ts:107

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

Returns​

string

Inherited from​

IndexStore.searchIndex


writeIndex​

Get Signature​

get writeIndex(): string

Defined in: index-store.ts:100

The most current indexed used to write to

Returns​

string

Inherited from​

IndexStore.writeIndex

Methods​

_ensureUnique()​

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

Defined in: index-model.ts:264

Parameters​

ParameterType
recordT
existing?T

Returns​

Promise<void>


_sanitizeRecord()​

protected _sanitizeRecord(record): T

Defined in: index-model.ts:226

Parameters​

ParameterType
recordT

Returns​

T


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

Defined in: index-store.ts:727

A small abstraction on client.search with retry support

Parameters​

ParameterType
paramsPartialParam<ClientParams.SearchParams>

Returns​

Promise<SearchResponse<T>>

Inherited from​

IndexStore._search


_toRecord()​

protected _toRecord(result, critical?): T

Defined in: index-store.ts:857

Parameters​

ParameterTypeDefault value
resultSearchResult<T>undefined
criticalbooleantrue

Returns​

T

Inherited from​

IndexStore._toRecord


_toRecords()​

protected _toRecords(results, critical?): T[]

Defined in: index-store.ts:869

Parameters​

ParameterTypeDefault value
resultsSearchResult<T>[]undefined
criticalbooleanfalse

Returns​

T[]

Inherited from​

IndexStore._toRecords


aggregate()​

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

Defined in: index-store.ts:711

Run an aggregation using an Elasticsearch Query DSL

Type Parameters​

Type ParameterDefault type
ASearchAggregations

Parameters​

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

Returns​

Promise<A>

Inherited from​

IndexStore.aggregate


appendToArray()​

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

Defined in: index-store.ts:776

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


bulk()​

Call Signature​

bulk(action, id): Promise<void>

Defined in: index-store.ts:126

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>

Todo​

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

Inherited from​

IndexStore.bulk

Call Signature​

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

Defined in: index-store.ts:127

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​
ParameterTypeDescription
action"index" | "create"-
docPartial<T>-
id?string-
retryOnConflict?number-
onBulkQueueConflict?OnBulkConflictFn<T>is used to detect and replace existing items in the bulk queue with the same name and action
Returns​

Promise<void>

Todo​

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

Inherited from​

IndexStore.bulk

Call Signature​

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

Defined in: index-store.ts:128

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​
ParameterTypeDescription
action"update"-
docPartial<T>-
id?string-
retryOnConflict?number-
onBulkQueueConflict?OnBulkConflictFn<T>is used to detect and replace existing items in the bulk queue with the same name and action
Returns​

Promise<void>

Todo​

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

Inherited from​

IndexStore.bulk

Call Signature​

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

Defined in: index-store.ts:129

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​
ParameterTypeDescription
action"upsert-with-script"-
scriptUpsertWithScript<T>-
id?string-
retryOnConflict?number-
onBulkQueueConflict?OnBulkConflictFn<T>is used to detect and replace existing items in the bulk queue with the same name and action
Returns​

Promise<void>

Todo​

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

Inherited from​

IndexStore.bulk


bulkCreateRecords()​

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

Defined in: index-model.ts:163

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

Parameters​

ParameterType
recordsCreateRecordInput<T>[]
allowOverrides?boolean

Returns​

Promise<void>


count()​

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

Defined in: index-store.ts:211

Count records by a given Lucene Query

Parameters​

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

Returns​

Promise<number>

Inherited from​

IndexStore.count


countBy()​

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

Defined in: index-store.ts:509

Parameters​

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

Returns​

Promise<number>

Inherited from​

IndexStore.countBy


countRecords()​

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

Defined in: index-model.ts:191

Parameters​

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

Returns​

Promise<number>


countRequest()​

countRequest(params): Promise<number>

Defined in: index-store.ts:225

Count records by a given Elasticsearch Query DSL

Parameters​

ParameterType
paramsCountParams

Returns​

Promise<number>

Inherited from​

IndexStore.countRequest


create()​

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

Defined in: index-store.ts:255

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


createById()​

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

Defined in: index-store.ts:243

Create a document with an id

Parameters​

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

Returns​

Promise<T>

the created record

Inherited from​

IndexStore.createById


createJoinQuery()​

createJoinQuery(fields, joinBy?, variables?): xLuceneQueryResult

Defined in: index-store.ts:761

Parameters​

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

Returns​

xLuceneQueryResult

Inherited from​

IndexStore.createJoinQuery


createRecord()​

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

Defined in: index-model.ts:117

Parameters​

ParameterType
recordCreateRecordInput<T>
allowOverrides?boolean

Returns​

Promise<T>


deleteById()​

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

Defined in: index-store.ts:401

Deletes a document for a given id

Parameters​

ParameterType
idstring
params?PartialParam<DeleteParams, any>

Returns​

Promise<void>

Inherited from​

IndexStore.deleteById


deleteRecord()​

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

Defined in: index-model.ts:176

Soft deletes a record by ID

Parameters​

ParameterType
idstring
clientId?number

Returns​

Promise<boolean>


exists()​

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

Defined in: index-store.ts:520

Parameters​

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

Returns​

Promise<boolean>

Inherited from​

IndexStore.exists


fetchRecord()​

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

Defined in: index-model.ts:102

Fetch a record by any unique ID

Parameters​

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

Returns​

Promise<T>


findAll()​

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

Defined in: index-store.ts:620

Parameters​

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

Returns​

Promise<T[]>

Inherited from​

IndexStore.findAll


findAllBy()​

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

Defined in: index-store.ts:569

Parameters​

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

Returns​

Promise<T[]>

Inherited from​

IndexStore.findAllBy


findAndApply()​

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

Defined in: index-store.ts:601

Parameters​

ParameterType
updatesPartial<T> | undefined
options?FindOneOptions<T>
queryAccess?QueryAccess<T>

Returns​

Promise<Partial<T>>

Inherited from​

IndexStore.findAndApply


findBy()​

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

Defined in: index-store.ts:535

Parameters​

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

Returns​

Promise<T>

Inherited from​

IndexStore.findBy


findById()​

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

Defined in: index-store.ts:587

Parameters​

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

Returns​

Promise<T>

Inherited from​

IndexStore.findById


flush()​

flush(flushAll?): Promise<void>

Defined in: index-store.ts:279

Parameters​

ParameterTypeDefault value
flushAllbooleanfalse

Returns​

Promise<void>

Inherited from​

IndexStore.flush


get()​

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

Defined in: index-store.ts:296

Get a single document

Parameters​

ParameterType
idstring
params?PartialParam<GetParams, any>

Returns​

Promise<T>

Inherited from​

IndexStore.get


getDefaultParams()​

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

Defined in: index-store.ts:499

Type Parameters​

Type ParameterDefault type
P extends Record<string, any>object

Parameters​

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

Returns​

P

Inherited from​

IndexStore.getDefaultParams


index()​

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

Defined in: index-store.ts:328

Index a document

Parameters​

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

Returns​

Promise<T>

Inherited from​

IndexStore.index


indexById()​

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

Defined in: index-store.ts:352

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


initialize()​

initialize(): Promise<void>

Defined in: index-store.ts:313

Connect and validate the index configuration.

Returns​

Promise<void>

Inherited from​

IndexStore.initialize


mget()​

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

Defined in: index-store.ts:363

Get multiple documents at the same time

Parameters​

ParameterType
bodyMGetBody
params?PartialParam<MGetParams, any>

Returns​

Promise<T[]>

Inherited from​

IndexStore.mget


migrateIndex()​

migrateIndex(options): Promise<any>

Defined in: index-store.ts:380

Parameters​

ParameterType
optionsMigrateIndexStoreOptions

Returns​

Promise<any>

See​

IndexManager#migrateIndex

Inherited from​

IndexStore.migrateIndex


recordExists()​

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

Defined in: index-model.ts:207

Parameters​

ParameterType
idstring | string[]
clientId?number

Returns​

Promise<boolean>


refresh()​

refresh(params?): Promise<void>

Defined in: index-store.ts:387

Refreshes the current index

Parameters​

ParameterType
params?PartialParam<IndicesRefreshParams, any>

Returns​

Promise<void>

Inherited from​

IndexStore.refresh


removeFromArray()​

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

Defined in: index-store.ts:806

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


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

Defined in: index-store.ts:656

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


searchRequest()​

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

Defined in: index-store.ts:691

Search using the underlying Elasticsearch Query DSL

Parameters​

ParameterType
paramsPartialParam<ClientParams.SearchParams>
critical?boolean

Returns​

Promise<SearchResult<T>>

Inherited from​

IndexStore.searchRequest


shutdown()​

shutdown(): Promise<void>

Defined in: index-store.ts:422

Shutdown, flush any pending requests and cleanup

Returns​

Promise<void>

Inherited from​

IndexStore.shutdown


update()​

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

Defined in: index-store.ts:435

Update a document with a given id

Parameters​

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

Returns​

Promise<void>

Inherited from​

IndexStore.update


updatePartial()​

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

Defined in: index-store.ts:468

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


updateRecord()​

updateRecord(id, record): Promise<T>

Defined in: index-model.ts:144

Parameters​

ParameterType
idstring
recordUpdateRecordInput<T>

Returns​

Promise<T>