elasticsearch-store / index-model / IndexModel
Abstract Class: IndexModel<T>
Defined in: index-model.ts:21
A high-level, opinionated, abstract class for an elasticsearch DataType, with a CRUD-like interface
Extends
IndexStore<T>
Type Parameters
| Type Parameter |
|---|
T extends IndexModelRecord |
Constructors
Constructor
new IndexModel<
T>(client,options,modelConfig):IndexModel<T>
Defined in: index-model.ts:28
Parameters
| Parameter | Type |
|---|---|
client | Client |
options | IndexModelOptions |
modelConfig | IndexModelConfig<T> |
Returns
IndexModel<T>
Overrides
Properties
| Property | Modifier | Type | Default value | Overrides | Inherited from | Defined in |
|---|---|---|---|---|---|---|
_defaultQueryAccess | protected | undefined | QueryAccess<T> | undefined | - | IndexStore._defaultQueryAccess | index-store.ts:34 |
client | readonly | Client | undefined | - | IndexStore.client | index-store.ts:28 |
clientMetadata | readonly | ClientMetadata | undefined | - | IndexStore.clientMetadata | index-store.ts:33 |
config | readonly | IndexConfig<T> | undefined | - | IndexStore.config | index-store.ts:29 |
logger | readonly | Logger | undefined | - | - | index-model.ts:23 |
manager | readonly | IndexManager | undefined | - | IndexStore.manager | index-store.ts:30 |
name | readonly | string | undefined | IndexStore.name | - | index-model.ts:22 |
readHooks | readonly | Set<ReadHook<T>> | undefined | - | IndexStore.readHooks | index-store.ts:38 |
refreshByDefault | public | boolean | true | - | IndexStore.refreshByDefault | index-store.ts:32 |
writeHooks | readonly | Set<WriteHook<T>> | undefined | - | IndexStore.writeHooks | index-store.ts:37 |
xLuceneTypeConfig | readonly | xLuceneTypeConfig | undefined | - | IndexStore.xLuceneTypeConfig | index-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
writeIndex
Get Signature
get writeIndex():
string
Defined in: index-store.ts:100
The most current indexed used to write to
Returns
string
Inherited from
Methods
_ensureUnique()
protected_ensureUnique(record,existing?):Promise<void>
Defined in: index-model.ts:263
Parameters
| Parameter | Type |
|---|---|
record | T |
existing? | T |
Returns
Promise<void>
_sanitizeRecord()
protected_sanitizeRecord(record):T
Defined in: index-model.ts:225
Parameters
| Parameter | Type |
|---|---|
record | T |
Returns
T
_search()
protected_search(params):Promise<SearchResponse<T>>
Defined in: index-store.ts:744
A small abstraction on client.search with retry support
Parameters
| Parameter | Type |
|---|---|
params | PartialParam<ClientParams.SearchParams> |
Returns
Promise<SearchResponse<T>>
Inherited from
_toRecord()
protected_toRecord(result,critical):T
Defined in: index-store.ts:874
Parameters
| Parameter | Type | Default value |
|---|---|---|
result | SearchResult<T> | undefined |
critical | boolean | true |
Returns
T
Inherited from
_toRecords()
protected_toRecords(results,critical):T[]
Defined in: index-store.ts:886
Parameters
| Parameter | Type | Default value |
|---|---|---|
results | SearchResult<T>[] | undefined |
critical | boolean | false |
Returns
T[]
Inherited from
aggregate()
aggregate<
A>(query,params?):Promise<A>
Defined in: index-store.ts:728
Run an aggregation using an Elasticsearch Query DSL
Type Parameters
| Type Parameter | Default type |
|---|---|
A | SearchAggregations |
Parameters
| Parameter | Type |
|---|---|
query | Record<string, any> |
params? | PartialParam<SearchParams, any> |
Returns
Promise<A>
Inherited from
appendToArray()
appendToArray(
id,field,values):Promise<void>
Defined in: index-store.ts:793
Append values from an array on a record. Use with caution, this may not work in all cases.
Parameters
| Parameter | Type |
|---|---|
id | string |
field | keyof T |
values | string | string[] |
Returns
Promise<void>
Inherited from
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
| Parameter | Type |
|---|---|
action | "delete" |
id | string |
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
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
| Parameter | Type | Description |
|---|---|---|
action | "index" | "create" | - |
doc | Partial<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
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
| Parameter | Type | Description |
|---|---|---|
action | "update" | - |
doc | Partial<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
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
| Parameter | Type | Description |
|---|---|---|
action | "upsert-with-script" | - |
script | UpsertWithScript<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
bulkCreateRecords()
bulkCreateRecords(
records,allowOverrides?):Promise<void>
Defined in: index-model.ts:162
Create a bulk records and put it them into bulk request queue
Parameters
| Parameter | Type |
|---|---|
records | CreateRecordInput<T>[] |
allowOverrides? | boolean |
Returns
Promise<void>
count()
count(
query?,options?,queryAccess?):Promise<number>
Defined in: index-store.ts:217
Count records by a given Lucene Query
Parameters
| Parameter | Type |
|---|---|
query? | string |
options? | RestrictOptions |
queryAccess? | QueryAccess<T> |
Returns
Promise<number>
Inherited from
countBy()
countBy(
fields,joinBy?,options?,queryAccess?):Promise<number>
Defined in: index-store.ts:526
Parameters
| Parameter | Type |
|---|---|
fields | AnyInput<T> |
joinBy? | JoinBy |
options? | RestrictOptions |
queryAccess? | QueryAccess<T> |
Returns
Promise<number>
Inherited from
countRecords()
countRecords(
fields,clientId?,joinBy?,options?,queryAccess?):Promise<number>
Defined in: index-model.ts:190
Parameters
| Parameter | Type |
|---|---|
fields | AnyInput<T> |
clientId? | number |
joinBy? | JoinBy |
options? | RestrictOptions |
queryAccess? | QueryAccess<T> |
Returns
Promise<number>
countRequest()
countRequest(
params):Promise<number>
Defined in: index-store.ts:231
Count records by a given Elasticsearch Query DSL
Parameters
| Parameter | Type |
|---|---|
params | CountParams |
Returns
Promise<number>
Inherited from
create()
create(
doc,params?):Promise<T>
Defined in: index-store.ts:261
Create a document but will throw if doc already exists
Parameters
| Parameter | Type |
|---|---|
doc | Partial<T> |
params? | PartialParam<CreateParams<T>, "body"> |
Returns
Promise<T>
the created record
Inherited from
createById()
createById(
id,doc,params?):Promise<T>
Defined in: index-store.ts:249
Create a document with an id
Parameters
| Parameter | Type |
|---|---|
id | string |
doc | Partial<T> |
params? | PartialParam<CreateParams<T>, "id" | "body"> |
Returns
Promise<T>
the created record
Inherited from
createJoinQuery()
createJoinQuery(
fields,joinBy,variables):xLuceneQueryResult
Defined in: index-store.ts:778
Parameters
| Parameter | Type | Default value |
|---|---|---|
fields | AnyInput<T> | undefined |
joinBy | JoinBy | 'AND' |
variables | { } | {} |
Returns
xLuceneQueryResult
Inherited from
createRecord()
createRecord(
record,allowOverrides?):Promise<T>
Defined in: index-model.ts:116
Parameters
| Parameter | Type |
|---|---|
record | CreateRecordInput<T> |
allowOverrides? | boolean |
Returns
Promise<T>
deleteById()
deleteById(
id,params?):Promise<void>
Defined in: index-store.ts:407
Deletes a document for a given id
Parameters
| Parameter | Type |
|---|---|
id | string |
params? | PartialParam<DeleteParams, any> |
Returns
Promise<void>
Inherited from
deleteRecord()
deleteRecord(
id,clientId?):Promise<boolean>
Defined in: index-model.ts:175
Soft deletes a record by ID
Parameters
| Parameter | Type |
|---|---|
id | string |
clientId? | number |
Returns
Promise<boolean>
exists()
exists(
id,options?,queryAccess?):Promise<boolean>
Defined in: index-store.ts:537
Parameters
| Parameter | Type |
|---|---|
id | string | string[] |
options? | RestrictOptions |
queryAccess? | QueryAccess<T> |
Returns
Promise<boolean>
Inherited from
fetchRecord()
fetchRecord(
anyId,options?,queryAccess?):Promise<T>
Defined in: index-model.ts:101
Fetch a record by any unique ID
Parameters
| Parameter | Type |
|---|---|
anyId | string |
options? | FindOneOptions<T> |
queryAccess? | QueryAccess<T> |
Returns
Promise<T>
findAll()
findAll(
ids,options?,queryAccess?):Promise<T[]>
Defined in: index-store.ts:637
Parameters
| Parameter | Type |
|---|---|
ids | undefined | string | string[] |
options? | FindOneOptions<T> |
queryAccess? | QueryAccess<T> |
Returns
Promise<T[]>
Inherited from
findAllBy()
findAllBy(
fields,joinBy?,options?,queryAccess?):Promise<T[]>
Defined in: index-store.ts:586
Parameters
| Parameter | Type |
|---|---|
fields | AnyInput<T> |
joinBy? | JoinBy |
options? | FindOptions<T> |
queryAccess? | QueryAccess<T> |
Returns
Promise<T[]>
Inherited from
findAndApply()
findAndApply(
updates,options?,queryAccess?):Promise<Partial<T>>
Defined in: index-store.ts:618
Parameters
| Parameter | Type |
|---|---|
updates | undefined | Partial<T> |
options? | FindOneOptions<T> |
queryAccess? | QueryAccess<T> |
Returns
Promise<Partial<T>>
Inherited from
findBy()
findBy(
fields,joinBy?,options?,queryAccess?):Promise<T>
Defined in: index-store.ts:552
Parameters
| Parameter | Type |
|---|---|
fields | AnyInput<T> |
joinBy? | JoinBy |
options? | FindOneOptions<T> |
queryAccess? | QueryAccess<T> |
Returns
Promise<T>
Inherited from
findById()
findById(
id,options?,queryAccess?):Promise<T>
Defined in: index-store.ts:604
Parameters
| Parameter | Type |
|---|---|
id | string |
options? | FindOneOptions<T> |
queryAccess? | QueryAccess<T> |
Returns
Promise<T>
Inherited from
flush()
flush(
flushAll):Promise<void>
Defined in: index-store.ts:285
Parameters
| Parameter | Type | Default value |
|---|---|---|
flushAll | boolean | false |
Returns
Promise<void>
Inherited from
get()
get(
id,params?):Promise<T>
Defined in: index-store.ts:302
Get a single document
Parameters
| Parameter | Type |
|---|---|
id | string |
params? | PartialParam<GetParams, any> |
Returns
Promise<T>
Inherited from
getDefaultParams()
getDefaultParams<
P>(index, ...params):P
Defined in: index-store.ts:509
Type Parameters
| Type Parameter | Default type |
|---|---|
P extends Record<string, any> | object |
Parameters
| Parameter | Type |
|---|---|
index | string |
...params | (undefined | Partial<P> & Record<string, any>)[] |
Returns
P
Inherited from
index()
index(
doc,params?):Promise<T>
Defined in: index-store.ts:334
Index a document
Parameters
| Parameter | Type |
|---|---|
doc | T | Partial<T> |
params? | PartialParam<IndexParams<T>, "body"> |
Returns
Promise<T>
Inherited from
indexById()
indexById(
id,doc,params?):Promise<T>
Defined in: index-store.ts:358
A convenience method for indexing a document with an ID
Parameters
| Parameter | Type |
|---|---|
id | string |
doc | T | Partial<T> |
params? | PartialParam<IndexParams<T>, "type" | "index" | "id"> |
Returns
Promise<T>
Inherited from
initialize()
initialize():
Promise<void>
Defined in: index-store.ts:319
Connect and validate the index configuration.
Returns
Promise<void>
Inherited from
mget()
mget(
body,params?):Promise<T[]>
Defined in: index-store.ts:369
Get multiple documents at the same time
Parameters
| Parameter | Type |
|---|---|
body | MGetBody |
params? | PartialParam<MGetParams, any> |
Returns
Promise<T[]>
Inherited from
migrateIndex()
migrateIndex(
options):Promise<any>
Defined in: index-store.ts:386
Parameters
| Parameter | Type |
|---|---|
options | MigrateIndexStoreOptions |
Returns
Promise<any>
See
IndexManager#migrateIndex
Inherited from
recordExists()
recordExists(
id,clientId?):Promise<boolean>
Defined in: index-model.ts:206
Parameters
| Parameter | Type |
|---|---|
id | string | string[] |
clientId? | number |
Returns
Promise<boolean>
refresh()
refresh(
params?):Promise<void>
Defined in: index-store.ts:393
Refreshes the current index
Parameters
| Parameter | Type |
|---|---|
params? | PartialParam<IndicesRefreshParams, any> |
Returns
Promise<void>
Inherited from
removeFromArray()
removeFromArray(
id,field,values):Promise<void>
Defined in: index-store.ts:823
Remove values from an array on a record. Use with caution, this may not work in all cases.
Parameters
| Parameter | Type |
|---|---|
id | string |
field | keyof T |
values | string | string[] |
Returns
Promise<void>
Inherited from
search()
search(
q?,options?,queryAccess?,critical?):Promise<SearchResult<T>>
Defined in: index-store.ts:673
Search with a given Lucene Query
Parameters
| Parameter | Type |
|---|---|
q? | string |
options? | FindOptions<T> |
queryAccess? | QueryAccess<T> |
critical? | boolean |
Returns
Promise<SearchResult<T>>
Inherited from
searchRequest()
searchRequest(
params,critical?):Promise<SearchResult<T>>
Defined in: index-store.ts:708
Search using the underlying Elasticsearch Query DSL
Parameters
| Parameter | Type |
|---|---|
params | PartialParam<ClientParams.SearchParams> |
critical? | boolean |
Returns
Promise<SearchResult<T>>
Inherited from
shutdown()
shutdown():
Promise<void>
Defined in: index-store.ts:428
Shutdown, flush any pending requests and cleanup
Returns
Promise<void>
Inherited from
update()
update(
id,body,params?):Promise<void>
Defined in: index-store.ts:441
Update a document with a given id
Parameters
| Parameter | Type |
|---|---|
id | string |
body | UpdateBody<T> |
params? | PartialParam<UpdateParams<unknown, unknown>, "id" | "body"> |
Returns
Promise<void>
Inherited from
updatePartial()
updatePartial(
id,applyChanges,retriesOnConflict):Promise<T>
Defined in: index-store.ts:474
Safely apply updates to a document by applying the latest changes
Parameters
| Parameter | Type | Default value |
|---|---|---|
id | string | undefined |
applyChanges | ApplyPartialUpdates<T> | undefined |
retriesOnConflict | number | 3 |
Returns
Promise<T>
Inherited from
updateRecord()
updateRecord(
id,record):Promise<T>
Defined in: index-model.ts:143
Parameters
| Parameter | Type |
|---|---|
id | string |
record | UpdateRecordInput<T> |
Returns
Promise<T>