Skip to main content

ElasticSearchService

@webda/elasticsearch


Class: ElasticSearchService<T>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:126

Index a Model allowing you to query it through ES

Webda Modda​

Extends​

  • Service<T>

Type Parameters​

T​

T extends ElasticSearchServiceParameters = ElasticSearchServiceParameters

Constructors​

Constructor​

new ElasticSearchService<T>(name, params): ElasticSearchService<T>

Defined in: packages/core/lib/services/service.d.ts:72

Service

Parameters​

name​

string

The name of the service

params​

T

The parameters block define in the configuration file

Returns​

ElasticSearchService<T>

Inherited from​

Service<T>.constructor

Properties​

_client​

_client: Client

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:129


_compiledCapabilities​

protected _compiledCapabilities: Record<string, any>

Defined in: packages/core/lib/services/iservice.d.ts:39

Capabilities detected at compile-time from @WebdaCapability-tagged interfaces.

Populated during Service.resolve by reading the service's entry in webda.module.json. Each key is a capability name (e.g., "request-filter"), and the value is an empty object {} by default. Override getCapabilities to provide capability-specific configuration or to conditionally disable capabilities.

See​

getCapabilities

Inherited from​

Service._compiledCapabilities


_refreshMode​

_refreshMode: boolean | "wait_for" = false

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:130


[WEBDA_EVENTS]​

[WEBDA_EVENTS]: object

Defined in: packages/core/lib/services/service.d.ts:50

Set the Webda events here

Inherited from​

Service.[WEBDA_EVENTS]


indexes​

protected indexes: object = {}

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:131

Index Signature​

[key: string]: IndexInfo


logger​

protected logger: Logger

Defined in: packages/core/lib/services/service.d.ts:59

Logger with class context

Inherited from​

Service.logger


metrics?​

protected optional metrics?: object

Defined in: packages/core/lib/services/service.d.ts:63

Get metrics

Inherited from​

Service.metrics


name​

readonly name: string

Defined in: packages/core/lib/services/iservice.d.ts:19

Inherited from​

Service.name


parameters​

readonly parameters: T

Defined in: packages/core/lib/services/iservice.d.ts:20

Inherited from​

Service.parameters


createConfiguration?​

static optional createConfiguration?: (params) => any

Defined in: packages/core/lib/services/iservice.d.ts:24

Create configuration set by the application on load

Parameters​

params​

any

Returns​

any

Inherited from​

Service.createConfiguration


filterConfiguration?​

static optional filterConfiguration?: (params) => any

Defined in: packages/core/lib/services/iservice.d.ts:28

Create configuration set by the application on load

Parameters​

params​

any

Returns​

any

Inherited from​

Service.filterConfiguration


Parameters​

static Parameters: typeof ServiceParameters

Defined in: packages/core/lib/services/service.d.ts:46

Service parameters

Inherited from​

Service.Parameters

Methods​

__clean()​

__clean(): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:643

Remove all documents from the indexes

Returns​

Promise<void>

Overrides​

Service.__clean


_addItem()​

protected _addItem(index, uuid, property, item): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:422

Add an element to an array of the document

Parameters​

index​

string

the index name

uuid​

string

the document id

property​

string

the array property

item​

any

the item to add

Returns​

Promise<void>


_create()​

protected _create(index, uuid, object): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:528

Create a document in the index

Parameters​

index​

string

the index name

uuid​

string

the document id

object​

any

the object to index

Returns​

Promise<void>


_delete()​

protected _delete(index, uuid): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:504

Delete a document from the index

Parameters​

index​

string

the index to delete from

uuid​

string

the document id

Returns​

Promise<void>


_deleteAttribute()​

protected _deleteAttribute(index, uuid, property): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:485

Delete an attribute from a document

Parameters​

index​

string

the index name

uuid​

string

the document id

property​

string

the attribute to remove

Returns​

Promise<void>


_deleteItem()​

protected _deleteItem(index, uuid, property, element): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:465

Delete an item from an array on the document

Parameters​

index​

string

the index name

uuid​

string

the document id

property​

string

the array property

element​

number

the position to remove

Returns​

Promise<void>


_increments()​

protected _increments(index, uuid, parameters): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:351

Increments one or several properties of an object

Parameters​

index​

string

the index name

uuid​

string

the document id

parameters​

object[]

the properties to increment

Returns​

Promise<void>


_setItem()​

protected _setItem(index, uuid, property, idx, item): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:444

Replace an element of an array of the document

Parameters​

index​

string

the index name

uuid​

string

the document id

property​

string

the array property

idx​

number

the position to replace

item​

any

the new item

Returns​

Promise<void>


_update()​

protected _update(index, uuid, object): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:544

Update a document in the index, creating it if needed

Parameters​

index​

string

the index name

uuid​

string

the document id

object​

any

the fields to update

Returns​

Promise<void>


addListener()​

addListener<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:80

Type Parameters​

Key​

Key extends never

Parameters​

eventName​

Key

the event name

listener​

(event) => void | Promise<void>

the event listener

Returns​

this

this for chaining

See​

EventEmitter.addListener

Inherited from​

Service.addListener


addRoute()​

protected addRoute(url, methods, executer, openapi?, override?): void

Defined in: packages/core/lib/services/service.d.ts:177

Add a route dynamicaly

Parameters​

url​

string

of the route can contains dynamic part like {uuid}

methods​

HttpMethodType[]

the HTTP methods

executer​

Function

Method to execute for this route

openapi?​

OpenAPIWebdaDefinition

the OpenAPI specification

override?​

boolean

whether to override existing

Returns​

void

Inherited from​

Service.addRoute


authorizeClientEvent()​

authorizeClientEvent(_event, _context): boolean

Defined in: packages/core/lib/services/service.d.ts:153

Authorize a public event subscription

Parameters​

_event​

string

the event name

_context​

OperationContext

the execution context

Returns​

boolean

true if the condition is met

Inherited from​

Service.authorizeClientEvent


checkIndex()​

checkIndex(index): IndexInfo

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:560

Check an index is available or throw an exception

Parameters​

index​

string

the index name

Returns​

IndexInfo

the index information


computeParameters()​

computeParameters(): void

Defined in: packages/core/lib/services/service.d.ts:77

Used to compute or derivate input parameter to attribute

Returns​

void

Deprecated​

Inherited from​

Service.computeParameters


count()​

count(index?): Promise<number>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:613

Count all objects inside ES or if an index is defined all the objects from an index

Parameters​

index?​

string = undefined

the index name

Returns​

Promise<number>

the number of documents


emit()​

emit<Key>(event, data): Promise<void>

Defined in: packages/core/lib/services/service.d.ts:204

Emit the event with data and wait for Promise to finish if listener returned a Promise

Type Parameters​

Key​

Key extends never

Parameters​

event​

Key

the event name

data​

object[Key]

the data to process

Returns​

Promise<void>

Inherited from​

Service.emit


exists()​

exists(index, uuid): Promise<boolean>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:596

Check if an object exists in the index

Parameters​

index​

string

the index name

uuid​

string

the document id

Returns​

Promise<boolean>

true if the document exists


flush()​

flush(index): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:633

Wait for all event to be processed

Parameters​

index​

string

the index name

Returns​

Promise<void>


getCapabilities()​

getCapabilities(): Record<string, any>

Defined in: packages/core/lib/services/iservice.d.ts:61

Return the capabilities of this service.

By default returns capabilities detected at compile-time from

Returns​

Record<string, any>

the result

Webda Capability-tagged​

interfaces in webda.module.json.

Override to disable capabilities based on configuration:

getCapabilities() {
const caps = super.getCapabilities();
if (!this.parameters.enabled) delete caps["request-filter"];
return caps;
}

Inherited from​

Service.getCapabilities


getClient()​

getClient(): Client

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:663

Return ElasticSearch client

Returns​

Client

the client


getClientEvents()​

getClientEvents(): string[]

Defined in: packages/core/lib/services/service.d.ts:144

Return the events that an external system can subscribe to

Returns​

string[]

the list of results

Inherited from​

Service.getClientEvents


getMaxListeners()​

getMaxListeners(): number

Defined in: packages/core/lib/events/asynceventemitter.d.ts:84

Returns​

number

Inherited from​

Service.getMaxListeners


getMetric()​

getMetric<T>(type, configuration): T

Defined in: packages/core/lib/services/service.d.ts:138

Add service name label

Type Parameters​

T​

T = Gauge<string> | Counter<string> | Histogram<string>

Parameters​

type​

CustomConstructor<T, [MetricConfiguration<T>]>

the type to look up

configuration​

MetricConfiguration<T>

the configuration

Returns​

T

the result

Inherited from​

Service.getMetric


getName()​

getName(): string

Defined in: packages/core/lib/services/service.d.ts:209

Get service name

Returns​

string

the result string

Inherited from​

Service.getName


getOpenApiReplacements()​

getOpenApiReplacements(): any

Defined in: packages/core/lib/services/service.d.ts:182

Return variables for replacement in openapi

Returns​

any

the result

Inherited from​

Service.getOpenApiReplacements


getOperationId()​

getOperationId(id): string

Defined in: packages/core/lib/services/service.d.ts:167

If undefined is returned it cancel the operation registration

Parameters​

id​

string

the identifier

Returns​

string

the result

Inherited from​

Service.getOperationId


getParameters()​

getParameters(): T

Defined in: packages/core/lib/services/service.d.ts:82

Get the service parameters

Returns​

T

the result

Inherited from​

Service.getParameters


getService()​

getService<T>(name): ServicesMap[T]

Defined in: packages/core/lib/services/service.d.ts:131

Get a service by name

Type Parameters​

T​

T extends keyof ServicesMap

Parameters​

name​

T

the name to use

Returns​

ServicesMap[T]

the result map

Deprecated​

Use useService, might reconsider

Inherited from​

Service.getService


getState()​

getState(): ServiceStates

Defined in: packages/core/lib/services/service.d.ts:55

Get the current state

Returns​

ServiceStates

the result

Inherited from​

Service.getState


getTimedIndex()​

getTimedIndex(index, object): string

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:382

Return the timed index for the target object

Parameters​

index​

string

the index name

object​

any

the object to index

Returns​

string

the index name including the date suffix if needed


getTimedIndexFromUuid()​

getTimedIndexFromUuid(index, uuid): Promise<string>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:409

Return the timed index for an object stored in the repository

Parameters​

index​

string

the index name

uuid​

string

the object primary key

Returns​

Promise<string>

the index name including the date suffix if needed


getUrl()​

getUrl(url, _methods): string

Defined in: packages/core/lib/services/service.d.ts:161

Return the full path url based on parameters

Parameters​

url​

string

relative url to service

_methods​

HttpMethodType[]

in case we need filtering (like Store)

Returns​

string

absolute url or undefined if need to skip the Route

Inherited from​

Service.getUrl


init()​

init(): Promise<ElasticSearchService<T>>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:149

Listen to the repositories of the indexed models

Returns​

Promise<ElasticSearchService<T>>

this

Overrides​

Service.init


initMetrics()​

initMetrics(): void

Defined in: packages/core/lib/services/service.d.ts:124

Init the metrics

Returns​

void

Inherited from​

Service.initMetrics


initOperations()​

initOperations(): void

Defined in: packages/core/lib/services/service.d.ts:186

Init the operations from

Returns​

void

Operation​

decorators on this service

Inherited from​

Service.initOperations


isIndexed()​

protected isIndexed(index, uuid, object?): Promise<boolean>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:218

Check if an object belongs to the indexed model

The repository can be shared with parent or child models

Parameters​

index​

IndexInfo

the index information

uuid​

string

the object primary key

object?​

any

the object if available

Returns​

Promise<boolean>

true if the object should be indexed


listeners()​

listeners(eventName): Function[]

Defined in: packages/core/lib/events/asynceventemitter.d.ts:139

Get all listeners for an event

Parameters​

eventName​

never

the event name

Returns​

Function[]

the list of results

Inherited from​

Service.listeners


loadCapabilities()​

protected loadCapabilities(): void

Defined in: packages/core/lib/services/service.d.ts:120

Load capabilities from webda.module.json metadata into _compiledCapabilities.

Called during resolve after dependency injection. Reads the service's type name from parameters, looks it up in the application's module metadata (moddas or beans section), and populates _compiledCapabilities with an empty object for each declared capability name.

Fails silently if the application is not available (e.g., in unit tests where services are instantiated without a full application context).

Returns​

void

Example​

// If webda.module.json contains:
// { "moddas": { "MyApp/HawkService": { "capabilities": ["request-filter", "cors-filter"] } } }
// Then after resolve(), this.getCapabilities() returns:
// { "request-filter": {}, "cors-filter": {} }

See​

getCapabilities

Inherited from​

Service.loadCapabilities


log()​

log(level, ...args): void

Defined in: packages/core/lib/services/service.d.ts:226

Parameters​

level​

WorkerLogLevel

to log

args​

...any[]

additional arguments

Returns​

void

Inherited from​

Service.log


off()​

off<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:116

Type Parameters​

Key​

Key extends never

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.off

Inherited from​

Service.off


on()​

on<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:102

Type Parameters​

Key​

Key extends never

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.once

Inherited from​

Service.on


once()​

once<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:95

Type Parameters​

Key​

Key extends never

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.once

Inherited from​

Service.once


onDeleted()​

protected onDeleted(index, uuid): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:254

Remove a deleted object from the index

As the object is already deleted, it cannot be checked against the model so a missing document is ignored

Parameters​

index​

IndexInfo

the index information

uuid​

string

the deleted object primary key

Returns​

Promise<void>


onObject()​

protected onObject(index, uuid, object, create?): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:235

Index a created, updated or patched object

Parameters​

index​

IndexInfo

the index information

uuid​

string

the object primary key

object​

any

the object or the patched fields

create?​

boolean = false

true if the object was just created

Returns​

Promise<void>


onPartialUpdated()​

protected onPartialUpdated(index, evt): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:269

Replicate a partial update

Parameters​

index​

IndexInfo

the index information

evt​

any

the PartialUpdated event

Returns​

Promise<void>


reindex()​

reindex(index): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:298

Reindex a model

Parameters​

index​

string

the index name

Returns​

Promise<void>


removeAllListeners()​

removeAllListeners<Key>(eventName?): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:122

Type Parameters​

Key​

Key extends never

Parameters​

eventName?​

Key

the event name

Returns​

this

this for chaining

See​

EventEmitter.removeAllListeners

Inherited from​

Service.removeAllListeners


removeListener()​

removeListener<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:109

Type Parameters​

Key​

Key extends never

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.removeListener

Inherited from​

Service.removeListener


removeListeners()​

protected removeListeners(): void

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:168

Remove all the repository listeners

Returns​

void


resolve()​

resolve(): this

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:138

Create the ElasticSearch client

Returns​

this

this

Overrides​

Service.resolve


search<K>(index, query, from?): Promise<K[]>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:574

Search on Elastic search

Type Parameters​

K​

K = any

Parameters​

index​

string

the index name

query​

any

a query string or an ES query body

from?​

number = 0

offset of the first result

Returns​

Promise<K[]>

the models found


setMaxListeners()​

setMaxListeners(n): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:88

Parameters​

n​

number

Returns​

this

Inherited from​

Service.setMaxListeners


setRefreshMode()​

setRefreshMode(mode): void

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:625

Set the global type of refreshMode

Parameters​

mode​

boolean | "wait_for"

the refresh mode

Returns​

void


setupIndexes()​

protected setupIndexes(): void

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:178

Resolve the indexed models and listen to their repositories events

Returns​

void


stop()​

stop(): Promise<void>

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:159

Remove the repository listeners and close the client

Returns​

Promise<void>

Overrides​

Service.stop


toDocument()​

protected toDocument(object): any

Defined in: packages/elasticsearch/src/elasticsearch.service.ts:517

Convert an object to a plain JSON document

Parameters​

object​

any

the object to convert

Returns​

any

the JSON document


toJSON()​

toJSON(): string

Defined in: packages/core/lib/services/service.d.ts:191

Prevent service to be serialized

Returns​

string

the result

Inherited from​

Service.toJSON


toString()​

toString(): string

Defined in: packages/core/lib/services/service.d.ts:91

Return service representation

Returns​

string

the result

Inherited from​

Service.toString