Elasticsearch Store: `Index Store Index Store`
index-store.IndexStore
A single index elasticsearch-store with some specific requirements around the index name, and record data
Type parameters
Name | Type |
---|---|
T | extends ts.AnyObject |
Hierarchy
IndexStore
Table of contents
Constructors
Properties
- _defaultQueryAccess
- client
- clientMetadata
- config
- manager
- name
- readHooks
- refreshByDefault
- writeHooks
- xLuceneTypeConfig
Accessors
Methods
- _search
- _toRecord
- _toRecords
- aggregate
- appendToArray
- bulk
- count
- countBy
- countRequest
- create
- createById
- createJoinQuery
- deleteById
- exists
- findAll
- findAllBy
- findAndApply
- findBy
- findById
- flush
- get
- getDefaultParams
- index
- indexById
- initialize
- mget
- migrateIndex
- refresh
- removeFromArray
- search
- searchRequest
- shutdown
- update
- updatePartial
Constructors
constructor
• new IndexStore<T
>(client
, config
): IndexStore
<T
>
Type parameters
Name | Type |
---|---|
T | extends AnyObject |
Parameters
Name | Type |
---|---|
client | Client |
config | IndexConfig <T > |
Returns
IndexStore
<T
>
Defined in
elasticsearch-store/src/index-store.ts:41
Properties
_defaultQueryAccess
• Protected
_defaultQueryAccess: undefined
| QueryAccess
<T
>
Defined in
elasticsearch-store/src/index-store.ts:25
client
• Readonly
client: Client
Defined in
elasticsearch-store/src/index-store.ts:19
clientMetadata
• Readonly
clientMetadata: ClientMetadata
Defined in
elasticsearch-store/src/index-store.ts:24
config
• Readonly
config: IndexConfig
<T
>
Defined in
elasticsearch-store/src/index-store.ts:20
manager
• Readonly
manager: IndexManager
Defined in
elasticsearch-store/src/index-store.ts:21
name
• Readonly
name: string
Defined in
elasticsearch-store/src/index-store.ts:22
readHooks
• Readonly
readHooks: Set
<ReadHook
<T
>>
Defined in
elasticsearch-store/src/index-store.ts:29
refreshByDefault
• refreshByDefault: boolean
= true
Defined in
elasticsearch-store/src/index-store.ts:23
writeHooks
• Readonly
writeHooks: Set
<WriteHook
<T
>>
Defined in
elasticsearch-store/src/index-store.ts:28
xLuceneTypeConfig
• Readonly
xLuceneTypeConfig: xLuceneTypeConfig
Defined in
elasticsearch-store/src/index-store.ts:26
Accessors
searchIndex
• get
searchIndex(): string
The index typically used for searching across all of the open indices
Returns
string
Defined in
elasticsearch-store/src/index-store.ts:98
writeIndex
• get
writeIndex(): string
The most current indexed used to write to
Returns
string
Defined in
elasticsearch-store/src/index-store.ts:91
Methods
_search
▸ _search(params
): Promise
<SearchResponse
<T
>>
A small abstraction on client.search with retry support
Parameters
Name | Type |
---|---|
params | PartialParam <SearchParams , any > |
Returns
Promise
<SearchResponse
<T
>>
Defined in
elasticsearch-store/src/index-store.ts:730
_toRecord
▸ _toRecord(result
, critical?
): T
Parameters
Name | Type | Default value |
---|---|---|
result | SearchResult <T > | undefined |
critical | boolean | true |
Returns
T
Defined in
elasticsearch-store/src/index-store.ts:860
_toRecords
▸ _toRecords(results
, critical?
): T
[]
Parameters
Name | Type | Default value |
---|---|---|
results | SearchResult <T >[] | undefined |
critical | boolean | false |
Returns
T
[]
Defined in
elasticsearch-store/src/index-store.ts:872
aggregate
▸ aggregate<A
>(query
, params?
): Promise
<A
>
Run an aggregation using an Elasticsearch Query DSL
Type parameters
Name | Type |
---|---|
A | SearchAggregations |
Parameters
Name | Type |
---|---|
query | Record <string , any > |
params? | PartialParam <SearchParams , any > |
Returns
Promise
<A
>
Defined in
elasticsearch-store/src/index-store.ts:714
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
Name | Type | |
---|---|---|
id | string | |
field | keyof T | |
values | string \ | string [] |
Returns
Promise
<void
>
Defined in
elasticsearch-store/src/index-store.ts:779
bulk
▸ 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
Name | 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
Defined in
elasticsearch-store/src/index-store.ts:117
▸ bulk(action
, doc
, id?
, retryOnConflict?
, onBulkQueueConflict?
): Promise
<void
>
Parameters
Name | Type | |
---|---|---|
action | "index" \ | "create" |
doc | Partial <T > | |
id? | string | |
retryOnConflict? | number | |
onBulkQueueConflict? | OnBulkConflictFn <T > |
Returns
Promise
<void
>
Defined in
elasticsearch-store/src/index-store.ts:118
▸ bulk(action
, doc
, id?
, retryOnConflict?
, onBulkQueueConflict?
): Promise
<void
>
Parameters
Name | Type |
---|---|
action | "update" |
doc | Partial <T > |
id? | string |
retryOnConflict? | number |
onBulkQueueConflict? | OnBulkConflictFn <T > |
Returns
Promise
<void
>
Defined in
elasticsearch-store/src/index-store.ts:119
▸ bulk(action
, script
, id?
, retryOnConflict?
, onBulkQueueConflict?
): Promise
<void
>
Parameters
Name | Type |
---|---|
action | "upsert-with-script" |
script | UpsertWithScript <T > |
id? | string |
retryOnConflict? | number |
onBulkQueueConflict? | OnBulkConflictFn <T > |
Returns
Promise
<void
>
Defined in
elasticsearch-store/src/index-store.ts:120
count
▸ count(query?
, options?
, queryAccess?
): Promise
<number
>
Count records by a given Lucene Query
Parameters
Name | Type |
---|---|
query? | string |
options? | RestrictOptions |
queryAccess? | QueryAccess <T > |
Returns
Promise
<number
>
Defined in
elasticsearch-store/src/index-store.ts:206
countBy
▸ countBy(fields
, joinBy?
, options?
, queryAccess?
): Promise
<number
>
Parameters
Name | Type |
---|---|
fields | AnyInput <T > |
joinBy? | JoinBy |
options? | RestrictOptions |
queryAccess? | QueryAccess <T > |
Returns
Promise
<number
>
Defined in
elasticsearch-store/src/index-store.ts:513
countRequest
▸ countRequest(params
): Promise
<number
>
Count records by a given Elasticsearch Query DSL
Parameters
Name | Type |
---|---|
params | CountParams |
Returns
Promise
<number
>
Defined in
elasticsearch-store/src/index-store.ts:220
create
▸ create(doc
, params?
): Promise
<T
>
Create a document but will throw if doc already exists
Parameters
Name | Type |
---|---|
doc | Partial <T > |
params? | PartialParam <CreateParams <T >, "body" > |
Returns
Promise
<T
>
the created record
Defined in
elasticsearch-store/src/index-store.ts:250
createById
▸ createById(id
, doc
, params?
): Promise
<T
>
Create a document with an id
Parameters
Name | Type | |
---|---|---|
id | string | |
doc | Partial <T > | |
params? | PartialParam <CreateParams <T >, "body" \ | "id" > |
Returns
Promise
<T
>
the created record
Defined in
elasticsearch-store/src/index-store.ts:238
createJoinQuery
▸ createJoinQuery(fields
, joinBy?
, variables?
): xLuceneQueryResult
Parameters
Name | Type | Default value |
---|---|---|
fields | AnyInput <T > | undefined |
joinBy | JoinBy | 'AND' |
variables | Object | {} |
Returns
xLuceneQueryResult
Defined in
elasticsearch-store/src/index-store.ts:764
deleteById
▸ deleteById(id
, params?
): Promise
<void
>
Deletes a document for a given id
Parameters
Name | Type |
---|---|
id | string |
params? | PartialParam <DeleteParams , any > |
Returns
Promise
<void
>
Defined in
elasticsearch-store/src/index-store.ts:396
exists
▸ exists(id
, options?
, queryAccess?
): Promise
<boolean
>
Parameters
Name | Type | |
---|---|---|
id | string \ | string [] |
options? | RestrictOptions | |
queryAccess? | QueryAccess <T > |
Returns
Promise
<boolean
>
Defined in
elasticsearch-store/src/index-store.ts:524
findAll
▸ findAll(ids
, options?
, queryAccess?
): Promise
<T
[]>
Parameters
Name | Type | ||
---|---|---|---|
ids | undefined \ | string \ | string [] |
options? | FindOneOptions <T > | ||
queryAccess? | QueryAccess <T > |
Returns
Promise
<T
[]>
Defined in
elasticsearch-store/src/index-store.ts:623
findAllBy
▸ findAllBy(fields
, joinBy?
, options?
, queryAccess?
): Promise
<T
[]>
Parameters
Name | Type |
---|---|
fields | AnyInput <T > |
joinBy? | JoinBy |
options? | FindOptions <T > |
queryAccess? | QueryAccess <T > |
Returns
Promise
<T
[]>
Defined in
elasticsearch-store/src/index-store.ts:573
findAndApply
▸ findAndApply(updates
, options?
, queryAccess?
): Promise
<Partial
<T
>>
Parameters
Name | Type | |
---|---|---|
updates | undefined \ | Partial <T > |
options? | FindOneOptions <T > | |
queryAccess? | QueryAccess <T > |
Returns
Promise
<Partial
<T
>>
Defined in
elasticsearch-store/src/index-store.ts:605
findBy
▸ findBy(fields
, joinBy?
, options?
, queryAccess?
): Promise
<T
>
Parameters
Name | Type |
---|---|
fields | AnyInput <T > |
joinBy? | JoinBy |
options? | FindOneOptions <T > |
queryAccess? | QueryAccess <T > |
Returns
Promise
<T
>
Defined in
elasticsearch-store/src/index-store.ts:539
findById
▸ findById(id
, options?
, queryAccess?
): Promise
<T
>
Parameters
Name | Type |
---|---|
id | string |
options? | FindOneOptions <T > |
queryAccess? | QueryAccess <T > |
Returns
Promise
<T
>
Defined in
elasticsearch-store/src/index-store.ts:591
flush
▸ flush(flushAll?
): Promise
<void
>
Parameters
Name | Type | Default value |
---|---|---|
flushAll | boolean | false |
Returns
Promise
<void
>
Defined in
elasticsearch-store/src/index-store.ts:274
get
▸ get(id
, params?
): Promise
<T
>
Get a single document
Parameters
Name | Type |
---|---|
id | string |
params? | PartialParam <GetParams , any > |
Returns
Promise
<T
>
Defined in
elasticsearch-store/src/index-store.ts:291
getDefaultParams
▸ getDefaultParams<P
>(index
, ...params
): P
Type parameters
Name | Type |
---|---|
P | extends Record <string , any > = { [prop: string] : any ; index : string } |
Parameters
Name | Type | |
---|---|---|
index | string | |
...params | (undefined \ | Partial <P > & Record <string , any >)[] |
Returns
P
Defined in
elasticsearch-store/src/index-store.ts:498
index
▸ index(doc
, params?
): Promise
<T
>
Index a document
Parameters
Name | Type | |
---|---|---|
doc | T \ | Partial <T > |
params? | PartialParam <IndexParams <T >, "body" > |
Returns
Promise
<T
>
Defined in
elasticsearch-store/src/index-store.ts:323
indexById
▸ indexById(id
, doc
, params?
): Promise
<T
>
A convenience method for indexing a document with an ID
Parameters
Name | Type | ||
---|---|---|---|
id | string | ||
doc | T \ | Partial <T > | |
params? | PartialParam <IndexParams <T >, "type" \ | "index" \ | "id" > |
Returns
Promise
<T
>
Defined in
elasticsearch-store/src/index-store.ts:347
initialize
▸ initialize(): Promise
<void
>
Connect and validate the index configuration.
Returns
Promise
<void
>
Defined in
elasticsearch-store/src/index-store.ts:308
mget
▸ mget(body
, params?
): Promise
<T
[]>
Get multiple documents at the same time
Parameters
Name | Type |
---|---|
body | MGetBody |
params? | PartialParam <MGetParams , any > |
Returns
Promise
<T
[]>
Defined in
elasticsearch-store/src/index-store.ts:358
migrateIndex
▸ migrateIndex(options
): Promise
<any
>
Parameters
Name | Type |
---|---|
options | MigrateIndexStoreOptions |
Returns
Promise
<any
>
See
IndexManager#migrateIndex
Defined in
elasticsearch-store/src/index-store.ts:375
refresh
▸ refresh(params?
): Promise
<void
>
Refreshes the current index
Parameters
Name | Type |
---|---|
params? | PartialParam <IndicesRefreshParams , any > |
Returns
Promise
<void
>
Defined in
elasticsearch-store/src/index-store.ts:382
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
Name | Type | |
---|---|---|
id | string | |
field | keyof T | |
values | string \ | string [] |
Returns
Promise
<void
>
Defined in
elasticsearch-store/src/index-store.ts:809
search
▸ search(q?
, options?
, queryAccess?
, critical?
): Promise
<SearchResult
<T
>>
Search with a given Lucene Query
Parameters
Name | Type |
---|---|
q? | string |
options? | FindOptions <T > |
queryAccess? | QueryAccess <T > |
critical? | boolean |
Returns
Promise
<SearchResult
<T
>>
Defined in
elasticsearch-store/src/index-store.ts:659
searchRequest
▸ searchRequest(params
, critical?
): Promise
<SearchResult
<T
>>
Search using the underlying Elasticsearch Query DSL
Parameters
Name | Type |
---|---|
params | PartialParam <SearchParams , any > |
critical? | boolean |
Returns
Promise
<SearchResult
<T
>>
Defined in
elasticsearch-store/src/index-store.ts:694
shutdown
▸ shutdown(): Promise
<void
>
Shutdown, flush any pending requests and cleanup
Returns
Promise
<void
>
Defined in
elasticsearch-store/src/index-store.ts:417
update
▸ update(id
, body
, params?
): Promise
<void
>
Update a document with a given id
Parameters
Name | Type | |
---|---|---|
id | string | |
body | UpdateBody <T > | |
params? | PartialParam <UpdateParams <unknown , unknown >, "body" \ | "id" > |
Returns
Promise
<void
>
Defined in
elasticsearch-store/src/index-store.ts:430
updatePartial
▸ updatePartial(id
, applyChanges
, retriesOnConflict?
): Promise
<T
>
Safely apply updates to a document by applying the latest changes
Parameters
Name | Type | Default value |
---|---|---|
id | string | undefined |
applyChanges | ApplyPartialUpdates <T > | undefined |
retriesOnConflict | number | 3 |
Returns
Promise
<T
>