Skip to main content

elasticsearch-store / index-store / IndexStore

Class: IndexStore<T>

Defined in: elasticsearch-store/src/index-store.ts:28

A single index elasticsearch-store with some specific requirements around the index name, and record data

Extended by

Type Parameters

Type Parameter
T extends Record<string, any>

Constructors

new IndexStore()

new IndexStore<T>(client, config): IndexStore<T>

Defined in: elasticsearch-store/src/index-store.ts:51

Parameters

ParameterType
clientClient
configIndexConfig<T>

Returns

IndexStore<T>

Properties

PropertyModifierTypeDefault valueDefined in
_defaultQueryAccessprotectedundefined | QueryAccess<T>undefinedelasticsearch-store/src/index-store.ts:35
clientreadonlyClientundefinedelasticsearch-store/src/index-store.ts:29
clientMetadatareadonlyClientMetadataundefinedelasticsearch-store/src/index-store.ts:34
configreadonlyIndexConfig<T>undefinedelasticsearch-store/src/index-store.ts:30
managerreadonlyIndexManagerundefinedelasticsearch-store/src/index-store.ts:31
namereadonlystringundefinedelasticsearch-store/src/index-store.ts:32
readHooksreadonlySet<ReadHook<T>>undefinedelasticsearch-store/src/index-store.ts:39
refreshByDefaultpublicbooleantrueelasticsearch-store/src/index-store.ts:33
writeHooksreadonlySet<WriteHook<T>>undefinedelasticsearch-store/src/index-store.ts:38
xLuceneTypeConfigreadonlyxLuceneTypeConfigundefinedelasticsearch-store/src/index-store.ts:36

Accessors

searchIndex

Get Signature

get searchIndex(): string

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

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

Returns

string


writeIndex

Get Signature

get writeIndex(): string

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

The most current indexed used to write to

Returns

string

Methods

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

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

A small abstraction on client.search with retry support

Parameters

ParameterType
paramsPartialParam<SearchParams>

Returns

Promise<SearchResponse<T>>


_toRecord()

protected _toRecord(result, critical): T

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

Parameters

ParameterTypeDefault value
resultSearchResult<T>undefined
criticalbooleantrue

Returns

T


_toRecords()

protected _toRecords(results, critical): T[]

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

Parameters

ParameterTypeDefault value
resultsSearchResult<T>[]undefined
criticalbooleanfalse

Returns

T[]


aggregate()

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

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

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>


appendToArray()

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

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

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>


bulk()

Call Signature

bulk(action, id): Promise<void>

Defined in: elasticsearch-store/src/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
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

Call Signature

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

Defined in: elasticsearch-store/src/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"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

Call Signature

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

Defined in: elasticsearch-store/src/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"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

Call Signature

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

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

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


count()

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

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

Count records by a given Lucene Query

Parameters

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

Returns

Promise<number>


countBy()

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

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

Parameters

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

Returns

Promise<number>


countRequest()

countRequest(params): Promise<number>

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

Count records by a given Elasticsearch Query DSL

Parameters

ParameterType
paramsCountParams

Returns

Promise<number>


create()

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

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

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


createById()

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

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

Create a document with an id

Parameters

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

Returns

Promise<T>

the created record


createJoinQuery()

createJoinQuery(fields, joinBy, variables): xLuceneQueryResult

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

Parameters

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

Returns

xLuceneQueryResult


deleteById()

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

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

Deletes a document for a given id

Parameters

ParameterType
idstring
params?PartialParam<DeleteParams, any>

Returns

Promise<void>


exists()

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

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

Parameters

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

Returns

Promise<boolean>


findAll()

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

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

Parameters

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

Returns

Promise<T[]>


findAllBy()

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

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

Parameters

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

Returns

Promise<T[]>


findAndApply()

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

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

Parameters

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

Returns

Promise<Partial<T>>


findBy()

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

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

Parameters

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

Returns

Promise<T>


findById()

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

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

Parameters

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

Returns

Promise<T>


flush()

flush(flushAll): Promise<void>

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

Parameters

ParameterTypeDefault value
flushAllbooleanfalse

Returns

Promise<void>


get()

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

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

Get a single document

Parameters

ParameterType
idstring
params?PartialParam<GetParams, any>

Returns

Promise<T>


getDefaultParams()

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

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

Type Parameters

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

Parameters

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

Returns

P


index()

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

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

Index a document

Parameters

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

Returns

Promise<T>


indexById()

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

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

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>


initialize()

initialize(): Promise<void>

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

Connect and validate the index configuration.

Returns

Promise<void>


mget()

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

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

Get multiple documents at the same time

Parameters

ParameterType
bodyMGetBody
params?PartialParam<MGetParams, any>

Returns

Promise<T[]>


migrateIndex()

migrateIndex(options): Promise<any>

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

Parameters

ParameterType
optionsMigrateIndexStoreOptions

Returns

Promise<any>

See

IndexManager#migrateIndex


refresh()

refresh(params?): Promise<void>

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

Refreshes the current index

Parameters

ParameterType
params?PartialParam<IndicesRefreshParams, any>

Returns

Promise<void>


removeFromArray()

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

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

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>


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

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

Search with a given Lucene Query

Parameters

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

Returns

Promise<SearchResult<T>>


searchRequest()

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

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

Search using the underlying Elasticsearch Query DSL

Parameters

ParameterType
paramsPartialParam<SearchParams>
critical?boolean

Returns

Promise<SearchResult<T>>


shutdown()

shutdown(): Promise<void>

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

Shutdown, flush any pending requests and cleanup

Returns

Promise<void>


update()

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

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

Update a document with a given id

Parameters

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

Returns

Promise<void>


updatePartial()

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

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

Safely apply updates to a document by applying the latest changes

Parameters

ParameterTypeDefault value
idstringundefined
applyChangesApplyPartialUpdates<T>undefined
retriesOnConflictnumber3

Returns

Promise<T>