Co-authored-by: Tomas Della Vedova <delvedor@users.noreply.github.com> Co-authored-by: Tomas Della Vedova <delvedor@users.noreply.github.com>
86 lines
2.1 KiB
Plaintext
86 lines
2.1 KiB
Plaintext
[[advanced-config]]
|
|
=== Advanced configuration
|
|
|
|
If you need to customize the client behavior heavily, you are in the right
|
|
place! The client enables you to customize the following internals:
|
|
|
|
* `ConnectionPool` class
|
|
* `Connection` class
|
|
* `Serializer` class
|
|
|
|
NOTE: For information about the `Transport` class, refer to <<transport>>.
|
|
|
|
|
|
[discrete]
|
|
==== `ConnectionPool`
|
|
|
|
This class is responsible for keeping in memory all the {es} Connection that you
|
|
are using. There is a single Connection for every node. The connection pool
|
|
handles the resurrection strategies and the updates of the pool.
|
|
|
|
[source,js]
|
|
----
|
|
const { Client, ConnectionPool } = require('@elastic/elasticsearch')
|
|
|
|
class MyConnectionPool extends ConnectionPool {
|
|
markAlive (connection) {
|
|
// your code
|
|
super.markAlive(connection)
|
|
}
|
|
}
|
|
|
|
const client = new Client({
|
|
ConnectionPool: MyConnectionPool
|
|
})
|
|
----
|
|
|
|
|
|
[discrete]
|
|
==== `Connection`
|
|
|
|
This class represents a single node, it holds every information we have on the
|
|
node, such as roles, id, URL, custom headers and so on. The actual HTTP request
|
|
is performed here, this means that if you want to swap the default HTTP client
|
|
(Node.js core), you should override the `request` method of this class.
|
|
|
|
[source,js]
|
|
----
|
|
const { Client, Connection } = require('@elastic/elasticsearch')
|
|
|
|
class MyConnection extends Connection {
|
|
request (params, callback) {
|
|
// your code
|
|
}
|
|
}
|
|
|
|
const client = new Client({
|
|
Connection: MyConnection
|
|
})
|
|
----
|
|
|
|
|
|
[discrete]
|
|
==== `Serializer`
|
|
|
|
This class is responsible for the serialization of every request, it offers the
|
|
following methods:
|
|
|
|
* `serialize(object: any): string;` serializes request objects.
|
|
* `deserialize(json: string): any;` deserializes response strings.
|
|
* `ndserialize(array: any[]): string;` serializes bulk request objects.
|
|
* `qserialize(object: any): string;` serializes request query parameters.
|
|
|
|
[source,js]
|
|
----
|
|
const { Client, Serializer } = require('@elastic/elasticsearch')
|
|
|
|
class MySerializer extends Serializer {
|
|
serialize (object) {
|
|
// your code
|
|
}
|
|
}
|
|
|
|
const client = new Client({
|
|
Serializer: MySerializer
|
|
})
|
|
---- |