elasticsearch-store / index-store / IndexStore
Class: IndexStore<T>
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
>
Parameters
Parameter | Type |
---|---|
client | Client |
config | IndexConfig <T > |
Returns
IndexStore
<T
>
Source
elasticsearch-store/src/index-store.ts:51
Properties
_defaultQueryAccess
protected
_defaultQueryAccess:undefined
|QueryAccess
<T
>
Source
elasticsearch-store/src/index-store.ts:35
client
readonly
client:Client
Source
elasticsearch-store/src/index-store.ts:29
clientMetadata
readonly
clientMetadata:ClientMetadata
Source
elasticsearch-store/src/index-store.ts:34
config
readonly
config:IndexConfig
<T
>
Source
elasticsearch-store/src/index-store.ts:30
manager
readonly
manager:IndexManager
Source
elasticsearch-store/src/index-store.ts:31
name
readonly
name:string
Source
elasticsearch-store/src/index-store.ts:32
readHooks
readonly
readHooks:Set
<ReadHook
<T
>>
Source
elasticsearch-store/src/index-store.ts:39
refreshByDefault
refreshByDefault:
boolean
=true
Source
elasticsearch-store/src/index-store.ts:33
writeHooks
readonly
writeHooks:Set
<WriteHook
<T
>>
Source
elasticsearch-store/src/index-store.ts:38
xLuceneTypeConfig
readonly
xLuceneTypeConfig: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
_search()
protected
_search(params
):Promise
<SearchResponse
<T
>>
A small abstraction on client.search with retry support
Parameters
Parameter | Type |
---|---|
params | PartialParam <SearchParams , any > |
Returns
Promise
<SearchResponse
<T
>>
Source
elasticsearch-store/src/index-store.ts:744
_toRecord()
protected
_toRecord(result
,critical
):T
Parameters
Parameter | Type | Default value |
---|---|---|
result | SearchResult <T > | undefined |
critical | boolean | true |
Returns
T
Source
elasticsearch-store/src/index-store.ts:874
_toRecords()
protected
_toRecords(results
,critical
):T
[]
Parameters
Parameter | Type | Default value |
---|---|---|
results | SearchResult <T >[] | undefined |
critical | boolean | false |
Returns
T
[]
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 parameter | Value |
---|---|
A | SearchAggregations |
Parameters
Parameter | Type |
---|---|
query | Record <string , any > |
params ? | PartialParam <SearchParams , any > |
Returns
Promise
<A
>
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
Parameter | Type |
---|---|
id | string |
field | keyof T |
values | string | string [] |
Returns
Promise
<void
>
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
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
Source
elasticsearch-store/src/index-store.ts:127
bulk(action, doc, id, retryOnConflict, onBulkQueueConflict)
bulk(
action
,doc
,id
?,retryOnConflict
?,onBulkQueueConflict
?):Promise
<void
>
Parameters
Parameter | Type |
---|---|
action | "index" | "create" |
doc | Partial <T > |
id ? | string |
retryOnConflict ? | number |
onBulkQueueConflict ? | OnBulkConflictFn <T > |
Returns
Promise
<void
>
Source
elasticsearch-store/src/index-store.ts:128
bulk(action, doc, id, retryOnConflict, onBulkQueueConflict)
bulk(
action
,doc
,id
?,retryOnConflict
?,onBulkQueueConflict
?):Promise
<void
>
Parameters
Parameter | Type |
---|---|
action | "update" |
doc | Partial <T > |
id ? | string |
retryOnConflict ? | number |
onBulkQueueConflict ? | OnBulkConflictFn <T > |
Returns
Promise
<void
>
Source
elasticsearch-store/src/index-store.ts:129
bulk(action, script, id, retryOnConflict, onBulkQueueConflict)
bulk(
action
,script
,id
?,retryOnConflict
?,onBulkQueueConflict
?):Promise
<void
>
Parameters
Parameter | Type |
---|---|
action | "upsert-with-script" |
script | UpsertWithScript <T > |
id ? | string |
retryOnConflict ? | number |
onBulkQueueConflict ? | OnBulkConflictFn <T > |
Returns
Promise
<void
>
Source
elasticsearch-store/src/index-store.ts:130
count()
count(
query
?,options
?,queryAccess
?):Promise
<number
>
Count records by a given Lucene Query
Parameters
Parameter | Type |
---|---|
query ? | string |
options ? | RestrictOptions |
queryAccess ? | QueryAccess <T > |
Returns
Promise
<number
>
Source
elasticsearch-store/src/index-store.ts:218
countBy()
countBy(
fields
,joinBy
?,options
?,queryAccess
?):Promise
<number
>
Parameters
Parameter | Type |
---|---|
fields | AnyInput <T > |
joinBy ? | JoinBy |
options ? | RestrictOptions |
queryAccess ? | QueryAccess <T > |
Returns
Promise
<number
>
Source
elasticsearch-store/src/index-store.ts:527
countRequest()
countRequest(
params
):Promise
<number
>
Count records by a given Elasticsearch Query DSL
Parameters
Parameter | Type |
---|---|
params | CountParams |
Returns
Promise
<number
>
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
Parameter | Type |
---|---|
doc | Partial <T > |
params ? | PartialParam <CreateParams <T >, "body" > |
Returns
Promise
<T
>
the created record
Source
elasticsearch-store/src/index-store.ts:262
createById()
createById(
id
,doc
,params
?):Promise
<T
>
Create a document with an id
Parameters
Parameter | Type |
---|---|
id | string |
doc | Partial <T > |
params ? | PartialParam <CreateParams <T >, "body" | "id" > |
Returns
Promise
<T
>
the created record
Source
elasticsearch-store/src/index-store.ts:250
createJoinQuery()
createJoinQuery(
fields
,joinBy
,variables
):xLuceneQueryResult
Parameters
Parameter | Type | Default value |
---|---|---|
fields | AnyInput <T > | undefined |
joinBy | JoinBy | 'AND' |
variables | object | {} |
Returns
xLuceneQueryResult
Source
elasticsearch-store/src/index-store.ts:778
deleteById()
deleteById(
id
,params
?):Promise
<void
>
Deletes a document for a given id
Parameters
Parameter | Type |
---|---|
id | string |
params ? | PartialParam <DeleteParams , any > |
Returns
Promise
<void
>
Source
elasticsearch-store/src/index-store.ts:408
exists()
exists(
id
,options
?,queryAccess
?):Promise
<boolean
>
Parameters
Parameter | Type |
---|---|
id | string | string [] |
options ? | RestrictOptions |
queryAccess ? | QueryAccess <T > |
Returns
Promise
<boolean
>
Source
elasticsearch-store/src/index-store.ts:538
findAll()
findAll(
ids
,options
?,queryAccess
?):Promise
<T
[]>
Parameters
Parameter | Type |
---|---|
ids | undefined | string | string [] |
options ? | FindOneOptions <T > |
queryAccess ? | QueryAccess <T > |
Returns
Promise
<T
[]>
Source
elasticsearch-store/src/index-store.ts:637
findAllBy()
findAllBy(
fields
,joinBy
?,options
?,queryAccess
?):Promise
<T
[]>
Parameters
Parameter | Type |
---|---|
fields | AnyInput <T > |
joinBy ? | JoinBy |
options ? | FindOptions <T > |
queryAccess ? | QueryAccess <T > |
Returns
Promise
<T
[]>
Source
elasticsearch-store/src/index-store.ts:587
findAndApply()
findAndApply(
updates
,options
?,queryAccess
?):Promise
<Partial
<T
>>
Parameters
Parameter | Type |
---|---|
updates | undefined | Partial <T > |
options ? | FindOneOptions <T > |
queryAccess ? | QueryAccess <T > |
Returns
Promise
<Partial
<T
>>
Source
elasticsearch-store/src/index-store.ts:619
findBy()
findBy(
fields
,joinBy
?,options
?,queryAccess
?):Promise
<T
>
Parameters
Parameter | Type |
---|---|
fields | AnyInput <T > |
joinBy ? | JoinBy |
options ? | FindOneOptions <T > |
queryAccess ? | QueryAccess <T > |
Returns
Promise
<T
>
Source
elasticsearch-store/src/index-store.ts:553
findById()
findById(
id
,options
?,queryAccess
?):Promise
<T
>
Parameters
Parameter | Type |
---|---|
id | string |
options ? | FindOneOptions <T > |
queryAccess ? | QueryAccess <T > |
Returns
Promise
<T
>
Source
elasticsearch-store/src/index-store.ts:605
flush()
flush(
flushAll
):Promise
<void
>
Parameters
Parameter | Type | Default value |
---|---|---|
flushAll | boolean | false |
Returns
Promise
<void
>
Source
elasticsearch-store/src/index-store.ts:286
get()
get(
id
,params
?):Promise
<T
>
Get a single document
Parameters
Parameter | Type |
---|---|
id | string |
params ? | PartialParam <GetParams , any > |
Returns
Promise
<T
>
Source
elasticsearch-store/src/index-store.ts:303
getDefaultParams()
getDefaultParams<
P
>(index
, ...params
):P
Type parameters
Type parameter | Value |
---|---|
P extends Record <string , any > | object |
Parameters
Parameter | Type |
---|---|
index | string |
...params | (undefined | Partial <P > & Record <string , any >)[] |
Returns
P
Source
elasticsearch-store/src/index-store.ts:510
index()
index(
doc
,params
?):Promise
<T
>
Index a document
Parameters
Parameter | Type |
---|---|
doc | T | Partial <T > |
params ? | PartialParam <IndexParams <T >, "body" > |
Returns
Promise
<T
>
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
Parameter | Type |
---|---|
id | string |
doc | T | Partial <T > |
params ? | PartialParam <IndexParams <T >, "type" | "index" | "id" > |
Returns
Promise
<T
>
Source
elasticsearch-store/src/index-store.ts:359
initialize()
initialize():
Promise
<void
>
Connect and validate the index configuration.
Returns
Promise
<void
>
Source
elasticsearch-store/src/index-store.ts:320
mget()
mget(
body
,params
?):Promise
<T
[]>
Get multiple documents at the same time
Parameters
Parameter | Type |
---|---|
body | MGetBody |
params ? | PartialParam <MGetParams , any > |
Returns
Promise
<T
[]>
Source
elasticsearch-store/src/index-store.ts:370
migrateIndex()
migrateIndex(
options
):Promise
<any
>
Parameters
Parameter | Type |
---|---|
options | MigrateIndexStoreOptions |
Returns
Promise
<any
>
See
IndexManager#migrateIndex
Source
elasticsearch-store/src/index-store.ts:387
refresh()
refresh(
params
?):Promise
<void
>
Refreshes the current index
Parameters
Parameter | Type |
---|---|
params ? | PartialParam <IndicesRefreshParams , any > |
Returns
Promise
<void
>
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
Parameter | Type |
---|---|
id | string |
field | keyof T |
values | string | string [] |
Returns
Promise
<void
>
Source
elasticsearch-store/src/index-store.ts:823
search()
search(
q
?,options
?,queryAccess
?,critical
?):Promise
<SearchResult
<T
>>
Search with a given Lucene Query
Parameters
Parameter | Type |
---|---|
q ? | string |
options ? | FindOptions <T > |
queryAccess ? | QueryAccess <T > |
critical ? | boolean |
Returns
Promise
<SearchResult
<T
>>
Source
elasticsearch-store/src/index-store.ts:673
searchRequest()
searchRequest(
params
,critical
?):Promise
<SearchResult
<T
>>
Search using the underlying Elasticsearch Query DSL
Parameters
Parameter | Type |
---|---|
params | PartialParam <SearchParams , any > |
critical ? | boolean |
Returns
Promise
<SearchResult
<T
>>
Source
elasticsearch-store/src/index-store.ts:708
shutdown()
shutdown():
Promise
<void
>
Shutdown, flush any pending requests and cleanup
Returns
Promise
<void
>
Source
elasticsearch-store/src/index-store.ts:429
update()
update(
id
,body
,params
?):Promise
<void
>
Update a document with a given id
Parameters
Parameter | Type |
---|---|
id | string |
body | UpdateBody <T > |
params ? | PartialParam <UpdateParams <unknown , unknown >, "body" | "id" > |
Returns
Promise
<void
>
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
Parameter | Type | Default value |
---|---|---|
id | string | undefined |
applyChanges | ApplyPartialUpdates <T > | undefined |
retriesOnConflict | number | 3 |
Returns
Promise
<T
>