You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/advanced-config.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ For information about the `Transport` class, refer to [Transport](/reference/tra
19
19
20
20
## `ConnectionPool`[_connectionpool]
21
21
22
-
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.
22
+
This class is responsible for keeping in memory all the {{es}} connections 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.
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.
44
+
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 ([Undici `Pool`](https://undici.nodejs.org/#/docs/api/Pool.md)), you should override the `request` method of this class.
`@elastic/transport` provides two `Connection` implementations:
63
+
64
+
-`UndiciConnection`: manages HTTP connections using [Undici](https://undici.nodejs.org/), Node.js's high-performance HTTP client implementation; this is the default value of `Connection` and is recommended unless you have a use case that is not yet supported by Undici or `UndiciConnection`
65
+
-`HttpConnection`: manages HTTP connections using [the `http` package](https://nodejs.org/api/http.html) from Node.js's standard library
62
66
63
67
## `Serializer`[_serializer]
64
68
@@ -175,5 +179,5 @@ try {
175
179
176
180
## Migrate to v8 [_migrate_to_v8]
177
181
178
-
The Node.js client can be configured to emit an HTTP header `Accept: application/vnd.elasticsearch+json; compatible-with=7` which signals to Elasticsearch that the client is requesting `7.x` version of request and response bodies. This allows for upgrading from 7.x to 8.x version of Elasticsearch without upgrading everything at once. Elasticsearch should be upgraded first after the compatibility header is configured and clients should be upgraded second. To enable to setting, configure the environment variable `ELASTIC_CLIENT_APIVERSIONING` to `true`.
182
+
The Node.js client can be configured to emit an HTTP header `Accept: application/vnd.elasticsearch+json; compatible-with=7` which signals to {{es}} that the client is requesting `7.x` version of request and response bodies. This allows for upgrading from 7.x to 8.x version of {{es}} without upgrading everything at once. {{es}} should be upgraded first after the compatibility header is configured and clients should be upgraded second. To enable to setting, configure the environment variable `ELASTIC_CLIENT_APIVERSIONING` to `true`.
http agent [options](https://nodejs.org/api/http.html#http_new_agent_options), or a function that returns an actual http agent instance. If you want to disable the http agent use entirely (and disable the `keep-alive` feature), set the agent to `false`.
192
+
If using the default `UndiciConnection` from `@elastic/transport`, this value can be:
193
+
194
+
- an [Undici `PoolOptions` object](https://undici.nodejs.org/#/docs/api/Pool?id=parameter-pooloptions)
195
+
- a function that receives all connection-related options and returns an [Undici `Agent`](https://undici.nodejs.org/#/docs/api/Agent.md) instance (or any other object that follows [Undici's `Dispatch.request()`](https://undici.nodejs.org/#/docs/api/Dispatcher?id=dispatcherrequestoptions-callback) conventions)
196
+
197
+
If using the legacy `HttpConnection` from `@elastic/transport`, this value can be:
198
+
199
+
-[the options object passed to an `http.Agent`](https://nodejs.org/api/http.html#new-agentoptions)
200
+
- a function that returns an `http.Agent` (and thus also an [`https.Agent`](https://nodejs.org/api/https.html#class-httpsagent), or any implementation that follows the same conventions, like [`hpagent`](https://www.npmjs.com/package/hpagent))
201
+
-`false` to disable all agent usage, including the `keep-alive` feature
193
202
194
203
```js
195
204
constclient=newClient({
@@ -211,6 +220,10 @@ const client = new Client({
211
220
})
212
221
```
213
222
223
+
::::{warning}
224
+
If you have set [the `agent` option](/reference/basic-config.md#agent-config) on your client instance to a function and are using `UndiciConnection`—the default [`Connection`](/reference/advanced-config.md#_connection) value starting in 8.0—all `caFingerprint` and `tls` options will be ignored. It is your responsibility to ensure that your custom agent will properly verify HTTPS connections.
Copy file name to clipboardExpand all lines: docs/reference/client-helpers.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,7 @@ To create a new instance of the Bulk helper, access it as shown in the example a
93
93
```
94
94
95
95
`onSuccess`
96
-
: A function that is called for each successful operation in the bulk request, which includes the result from Elasticsearch along with the original document that was sent, or `null` for delete operations.
96
+
: A function that is called for each successful operation in the bulk request, which includes the result from {{es}} along with the original document that was sent, or `null` for delete operations.
97
97
98
98
```js
99
99
const b = client.helpers.bulk({
@@ -307,7 +307,7 @@ console.log(result)
307
307
308
308
Added in `v8.8.2`
309
309
310
-
If you need to modify documents in your datasource before it is sent to Elasticsearch, you can return an array in the `onDocument` function rather than an operation object. The first item in the array must be the operation object, and the second item must be the document or partial document object as you’d like it to be sent to Elasticsearch.
310
+
If you need to modify documents in your datasource before it is sent to {{es}}, you can return an array in the `onDocument` function rather than an operation object. The first item in the array must be the operation object, and the second item must be the document or partial document object as you’d like it to be sent to {{es}}.
Copy file name to clipboardExpand all lines: docs/reference/connecting.md
+50-4Lines changed: 50 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,6 +77,10 @@ When you start {{es}} for the first time you’ll see a distinct block like the
77
77
78
78
Depending on the circumstances there are two options for verifying the HTTPS connection, either verifying with the CA certificate itself or via the HTTP CA certificate fingerprint.
79
79
80
+
::::{warning}
81
+
If you have set [the `agent` option](/reference/basic-config.md#agent-config) on your client instance to a function and are using `UndiciConnection`—the default `Connection` value starting in 8.0—all `caFingerprint` and `tls` options will be ignored. It is your responsibility to ensure that your custom agent will properly verify HTTPS connections.
82
+
::::
83
+
80
84
### TLS configuration [auth-tls]
81
85
82
86
The generated root CA certificate can be found in the `certs` directory in your {{es}} config location (`$ES_CONF_PATH/certs/http_ca.crt`). If you’re running {{es}} in Docker there is [additional documentation for retrieving the CA certificate](docs-content://deploy-manage/deploy/self-managed/install-elasticsearch-with-docker.md).
@@ -332,7 +336,7 @@ The supported request specific options are:
332
336
| Option | Description |
333
337
| --- | ----------- |
334
338
|`ignore`|`number[]` - HTTP status codes which should not be considered errors for this request.<br>*Default:*`null`|
335
-
|`requestTimeout`|`number` or `string` - Max request timeout for the request in milliseconds. This overrides the client default, which is to not time out at all. See [Elasticsearch best practices for HTML clients](elasticsearch://reference/elasticsearch/configuration-reference/networking-settings.md#_http_client_configuration) for more info.<br>_Default:_ No timeout |
339
+
| `requestTimeout` | `number` or `string` - Max request timeout for the request in milliseconds. This overrides the client default, which is to not time out at all. See [{{es}} best practices for HTML clients](elasticsearch://reference/elasticsearch/configuration-reference/networking-settings.md#_http_client_configuration) for more info.<br>_Default:_ No timeout |connecting
336
340
|`retryOnTimeout`|`boolean` - Retry requests that have timed out.*Default:*`false`|
337
341
|`maxRetries`|`number` - Max number of retries for the request, it overrides the client default.<br>*Default:*`3`|
338
342
|`compression`|`string` or `boolean` - Enables body compression for the request.<br>*Options:*`false`, `'gzip'`<br>*Default:*`false`|
@@ -477,9 +481,9 @@ You can find the errors exported by the client in the table below.
477
481
478
482
## Keep-alive connections [keep-alive]
479
483
480
-
By default, the client uses persistent, keep-alive connections to reduce the overhead of creating a new HTTP connection for each Elasticsearch request. If you are using the default `UndiciConnection` connection class, it maintains a pool of 256 connections with a keep-alive of 10 minutes. If you are using the legacy `HttpConnection` connection class, it maintains a pool of 256 connections with a keep-alive of 1 minute.
484
+
By default, the client uses persistent, keep-alive connections to reduce the overhead of creating a new HTTP connection for each {{es}} request. If you are using the default `UndiciConnection` connection class, it maintains a pool of 256 connections with a keep-alive of 10 minutes. If you are using the legacy `HttpConnection` connection class, it maintains a pool of 256 connections with a keep-alive of 1 minute.
481
485
482
-
If you need to disable keep-alive connections, you can override the HTTP agent with your preferred [HTTP agent options](https://nodejs.org/api/http.md#http_new_agent_options):
486
+
If you need to disable keep-alive connections, you can override the HTTP agent with your preferred [HTTP agent options](/reference/basic-config.md#agent-config):
483
487
484
488
```js
485
489
constclient=newClient({
@@ -500,6 +504,48 @@ const client = new Client({
500
504
})
501
505
```
502
506
507
+
## Managing open connection limits [limit-open-connections]
508
+
509
+
Starting in client 9.0, when using `@elastic/transport` 9.2.0 or later, you can provide a custom `agent` function to share a singleton [Undici `Agent`](https://undici.nodejs.org/#/docs/api/Agent.md) instance that can enforce client-wide connection limits.
// `maxOrigins * connections` (50 in this case) is the total connection limit
516
+
const maxSocketAgent =newAgent({
517
+
keepAliveTimeout: 1000,
518
+
maxOrigins: 5,
519
+
connections: 10
520
+
})
521
+
522
+
const client =newClient({
523
+
node: '...',
524
+
auth: { ... },
525
+
agent: () =>maxSocketAgent
526
+
})
527
+
```
528
+
529
+
If using the legacy `HttpConnection`, you can use an [`Agent`](https://nodejs.org/api/https.html#class-httpsagent) singleton that enforces `maxTotalSockets`:
## Closing a client’s connections [close-connections]
504
550
505
551
If you would like to close all open connections being managed by an instance of the client, use the `close()` function:
@@ -513,4 +559,4 @@ client.close();
513
559
514
560
## Automatic product check [product-check]
515
561
516
-
Since v7.14.0, the client performs a required product check before the first call. This pre-flight product check allows the client to establish the version of Elasticsearch that it is communicating with. The product check requires one additional HTTP request to be sent to the server as part of the request pipeline before the main API call is sent. In most cases, this will succeed during the very first API call that the client sends. Once the product check completes, no further product check HTTP requests are sent for subsequent API calls.
562
+
Since v7.14.0, the client performs a required product check before the first call. This pre-flight product check allows the client to establish the version of {{es}} that it is communicating with. The product check requires one additional HTTP request to be sent to the server as part of the request pipeline before the main API call is sent. In most cases, this will succeed during the very first API call that the client sends. Once the product check completes, no further product check HTTP requests are sent for subsequent API calls.
Copy file name to clipboardExpand all lines: docs/reference/getting-started.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ mapped_pages:
6
6
7
7
# Getting started [getting-started-js]
8
8
9
-
This page guides you through the installation process of the Node.js client, shows you how to instantiate the client, and how to perform basic Elasticsearch operations with it.
9
+
This page guides you through the installation process of the Node.js client, shows you how to instantiate the client, and how to perform basic {{es}} operations with it.
10
10
11
11
12
12
### Requirements [_requirements]
@@ -28,7 +28,7 @@ Refer to the [*Installation*](/reference/installation.md) page to learn more.
28
28
29
29
### Connecting [_connecting]
30
30
31
-
You can connect to the Elastic Cloud using an API key and the Elasticsearch endpoint.
31
+
You can connect to the Elastic Cloud using an API key and the {{es}} endpoint.
Copy file name to clipboardExpand all lines: docs/reference/observability.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ mapped_pages:
5
5
6
6
# Observability [observability]
7
7
8
-
To observe and measure Elasticsearch client usage, several client features are provided.
8
+
To observe and measure {{es}} client usage, several client features are provided.
9
9
10
10
First, as of 8.15.0, the client provides native support for OpenTelemetry, which allows you to send client usage data to any endpoint that supports OpenTelemetry without having to make any changes to your JavaScript codebase.
11
11
@@ -17,9 +17,9 @@ All of these observability features are documented below.
17
17
18
18
## OpenTelemetry [_opentelemetry]
19
19
20
-
The client supports OpenTelemetry’s [zero-code instrumentation](https://opentelemetry.io/docs/zero-code/js/) to enable tracking each client request as an [OpenTelemetry span](https://opentelemetry.io/docs/concepts/signals/traces/#spans). These spans follow all of the [semantic OpenTelemetry conventions for Elasticsearch](https://opentelemetry.io/docs/specs/semconv/database/elasticsearch/) except for `db.query.text`.
20
+
The client supports OpenTelemetry’s [zero-code instrumentation](https://opentelemetry.io/docs/zero-code/js/) to enable tracking each client request as an [OpenTelemetry span](https://opentelemetry.io/docs/concepts/signals/traces/#spans). These spans follow all of the [semantic OpenTelemetry conventions for {{es}}](https://opentelemetry.io/docs/specs/semconv/database/elasticsearch/) except for `db.query.text`.
21
21
22
-
To start sending Elasticsearch trace data to your OpenTelemetry endpoint, follow [OpenTelemetry’s zero-code instrumentation guide](https://opentelemetry.io/docs/zero-code/js/), or the following steps:
22
+
To start sending {{es}} trace data to your OpenTelemetry endpoint, follow [OpenTelemetry’s zero-code instrumentation guide](https://opentelemetry.io/docs/zero-code/js/), or the following steps:
23
23
24
24
1. Install `@opentelemetry/api` and `@opentelemetry/auto-instrumentations-node` as Node.js dependencies
25
25
2. Export the following environment variables with the appropriate values:
Copy file name to clipboardExpand all lines: docs/reference/timeout-best-practices.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,5 +9,5 @@ Starting in 9.0.0, this client is configured to not time out any HTTP request by
9
9
10
10
Prior to 9.0, this client was configured by default to operate like many HTTP client libraries do, by using a relatively short (30 second) timeout on all requests sent to {{es}}, raising a `TimeoutError` when that time period elapsed without receiving a response.
11
11
12
-
If you need to set timeouts on Elasticsearch requests, setting the `requestTimeout` value to a millisecond value will cause this client to operate as it did prior to 9.0.
12
+
If you need to set timeouts on {{es}} requests, setting the `requestTimeout` value to a millisecond value will cause this client to operate as it did prior to 9.0.
Copy file name to clipboardExpand all lines: docs/reference/typescript.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ mapped_pages:
5
5
6
6
# TypeScript support [typescript]
7
7
8
-
The client offers a first-class support for TypeScript, shipping a complete set of type definitions of Elasticsearch’s API surface.
8
+
The client offers a first-class support for TypeScript, shipping a complete set of type definitions of {{es}}'s API surface.
9
9
10
10
The types are not 100% complete yet. Some APIs are missing (the newest ones, e.g. EQL), and others may contain some errors, but we are continuously pushing fixes & improvements. Contribute type fixes and improvements to [elasticsearch-specification github repository](https://github.com/elastic/elasticsearch-specification).
/** @property redaction Options for how to redact potentially sensitive data from metadata attached to `Error` objects
185
-
* @remarks Read https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/advanced-config.html#redaction for more details
185
+
* @remarks Read https://www.elastic.co/docs/reference/elasticsearch/clients/javascript/advanced-config#redaction for more details
186
186
* @defaultValue Configuration that will replace known sources of sensitive data */
187
187
redaction?: RedactionOptions
188
188
/** @property serverMode Setting to "serverless" will change some default behavior, like enabling compression and disabling features that assume the possibility of multiple Elasticsearch nodes.
@@ -443,7 +443,7 @@ export default class Client extends API {
443
443
444
444
/**
445
445
* Creates a child client instance that shared its connection pool with the parent client
0 commit comments